-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
217ec9c
commit 9cb1f85
Showing
17 changed files
with
5,728 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ docs/ | |
|
||
# Dotenv file | ||
.env | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/chainlink-brownie-contracts"] | ||
path = lib/chainlink-brownie-contracts | ||
url = https://github.com/smartcontractkit/chainlink-brownie-contracts | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/openzeppelin/openzeppelin-contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require('fs'); | ||
const {Location, ReturnType, CodeLanguage} = require('@chainlink/functions-toolkit'); | ||
|
||
const requestConfig = { | ||
source : fs.readFileSync('./functions/sources/alpacaBalance.js').toString(), | ||
codeLocation: Location.Inline, | ||
secrets:{alpacaKey: process.env.ALPACA_KEY, alpacaSecret: process.env.ALPACA_SECRET}, | ||
secretsLocation: Location.DONHosted, | ||
arges: [], | ||
codeLanguage: CodeLanguage.JavaScript, | ||
expectedReturnType: ReturnType.uint256 | ||
} | ||
|
||
module.exports = requestConfig; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const requestConfig = require("../configs/alpacaMintConfig.js") | ||
const {simulateScript, decodeResult} = require("@chainlink/functions-toolkit") | ||
|
||
async function main(){ | ||
const{responseByetsHexString, errorString, capturedTerminalOutput} = await simulateScript(requestConfig); | ||
if(responseByetsHexString){ | ||
console.log("Response: ", decodeResult(responseByetsHexString, requestConfig.expectedReturnType)) | ||
} | ||
if(errorString){ | ||
console.error("Error: ", errorString) | ||
} | ||
} | ||
main().catch((error)=>{ | ||
console.error(error) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
if( | ||
secrets.alpacaKey == "" || | ||
secrets.alpacaSecret == "" | ||
){ | ||
throw Error("Alpaca API Key and Secret are required"); | ||
} | ||
|
||
const alpacaRequest = Functions.Http.makeRequest({ | ||
url : "https://paper-api.alpaca.markets/v2/account", | ||
headers : { | ||
accept : "application/json", | ||
"APCA-API-KEY-ID" : secrets.alpacaKey, | ||
"APCA-API-SECRET-KEY" : secrets.alpacaSecret | ||
} | ||
}); | ||
|
||
const [response] = await Promise.all({alpacaRequest}); | ||
const portfolioBalance = response.data.portfolio_value; | ||
console.log("Alpaca portfolio balance: ", portfolioBalance); | ||
|
||
return Functions.encodeUint256(Math.round(portfolioBalance * 100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const{ | ||
SecretsManager | ||
} = require("@chainlink/functions-toolkit"); | ||
const ethers = require("ethers"); | ||
|
||
|
||
async function uploadSecrets(){ | ||
const routerAddress="0xb83E47C2bC239B3bf370bc41e1459A34b41238D0"; | ||
const donId = "fun-ethereum-sepolia-1"; | ||
const gatewayUrls = ["https://02.functions-gateway.testnet.chain.link/", "https://01.functions-gateway.testnet.chain.link/"]; | ||
|
||
const privateKey = process.env.PRIVATE_KEY; | ||
const rpcUrl = process.env.SEPOLIA_RPC_URL; | ||
const secrets = {alpacaKey: process.env.ALPACA_KEY, alpacaSecret: process.env.ALPACA_SECRET} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(rpcUrl); | ||
const wallet = new ethers.Wallet(privateKey); | ||
const signer = wallet.connect(provider); | ||
|
||
const secretsManager = new SecretsManager(signer, routerAddress, donId); | ||
await secretsManager.initialize(); | ||
|
||
const encryptedSecrets = await secretsManager.encryptSecrets(secrets); | ||
const slotIdNumber = 0; | ||
const expirationTineMinutes=1440; | ||
const uploadResult = await secretsManager.uploadEncryptedSecretsToDON({ | ||
encryptedSecretsHexstring: encryptedSecrets.encryptedSecrets, | ||
gatewayUrls: gatewayUrls, | ||
slotId: slotIdNumber, | ||
minutesUntilExpiration: expirationTineMinutes | ||
|
||
}) | ||
|
||
if(!uploadResult.success){ | ||
throw new Error("Failed to upload secrets to DON", uploadResult.errorMessage) | ||
} | ||
|
||
console.log("Secrets uploaded successfully", uploadResult); | ||
const donHostedSecretsVersion = parseInt(uploadResult.version); | ||
console.log("Secrets version", donHostedSecretsVersion); | ||
|
||
} | ||
|
||
uploadSecrets().catch((error)=>{ | ||
console.error(error) | ||
process.exit(1) | ||
}) |
Submodule chainlink-brownie-contracts
added at
f06ed4
Submodule openzeppelin-contracts
added at
dbb610
Oops, something went wrong.