Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5be50b0
Start draft PR
ItsHugoo Jun 7, 2025
1cb4771
Add Jest as dev dependency and update test script
ItsHugoo Jun 7, 2025
888b37b
Add heroes data with Iron Man details
ItsHugoo Jun 7, 2025
9d31ed2
Add Iron Man hero route
ItsHugoo Jun 7, 2025
69edf3d
Add test for Iron Man hero route
ItsHugoo Jun 7, 2025
fece527
Update package.json to support ES modules and Jest
ItsHugoo Jun 7, 2025
cd47932
Create .gitignore with common excludes
ItsHugoo Jun 7, 2025
a6873e7
Add Jest configuration for ES modules
ItsHugoo Jun 7, 2025
fe6cad7
Remove Jest config from package.json
ItsHugoo Jun 7, 2025
626e7bd
Simplify Jest configuration
ItsHugoo Jun 7, 2025
7c1a306
Add Babel configuration for module transformation
ItsHugoo Jun 7, 2025
adf4cc2
Update Jest configuration to use Babel
ItsHugoo Jun 7, 2025
d6f7d90
Use ES Module syntax for Babel configuration
ItsHugoo Jun 7, 2025
c2b70d1
Use CommonJS for Babel configuration
ItsHugoo Jun 7, 2025
78acad0
Update package.json with Jest and Babel configurations
ItsHugoo Jun 7, 2025
b285e57
Remove separate Jest configuration
ItsHugoo Jun 7, 2025
9913bfa
Remove separate Babel configuration
ItsHugoo Jun 7, 2025
5bf1b41
Update test to use CommonJS imports
ItsHugoo Jun 7, 2025
5955845
Update routes to use CommonJS export
ItsHugoo Jun 7, 2025
860b28a
Update heroes data to use CommonJS export
ItsHugoo Jun 7, 2025
00f6cfb
Update package.json to use CommonJS
ItsHugoo Jun 7, 2025
74f6470
Start draft PR
xLDVx Jun 7, 2025
6e9b03b
Merged branch pr-1-ItsHugoo-Koii-Task-Funder-Express for PR https://g…
xLDVx Jun 7, 2025
0d81f68
Update package.json for ES module support and Jest configuration
xLDVx Jun 7, 2025
62c1ec8
Refactor index.js for ES module support and test compatibility
xLDVx Jun 7, 2025
d91b0d9
Update index.test.js for Jest compatibility and improved test coverage
xLDVx Jun 7, 2025
ea14355
Add .babelrc for Babel configuration
xLDVx Jun 7, 2025
6af59bd
Update mock-crypto-prices test to use Jest syntax
xLDVx Jun 7, 2025
8e716ed
Update inputValidation test to use Jest syntax
xLDVx Jun 7, 2025
154ced2
Remove problematic Jest configuration and add jest-cucumber
xLDVx Jun 7, 2025
8561303
Consolidate Babel and Jest configurations in package.json
xLDVx Jun 7, 2025
0450aea
Empty .babelrc as configuration is now in package.json
xLDVx Jun 7, 2025
b96d0c4
Update mock-crypto-prices test to use @jest/globals
xLDVx Jun 7, 2025
62b07f3
Update inputValidation test to use @jest/globals
xLDVx Jun 7, 2025
f0726f3
Update index.test.js to use @jest/globals
xLDVx Jun 7, 2025
2b9516d
Add @jest/globals to dev dependencies
xLDVx Jun 7, 2025
1f78adf
Empty .babelrc as a placeholder
xLDVx Jun 7, 2025
e14df2c
Add placeholder heroRoutes test
xLDVx Jun 7, 2025
e113805
Add Jest configuration file to resolve transformation issues
xLDVx Jun 7, 2025
68e51b0
Remove old Jest configuration from package.json
xLDVx Jun 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
node_modules
node_modules/
dist/
.env
.env.funder
*.pem
__pycache__/
.DS_Store
*.log
.jest-cache/
coverage/
90 changes: 48 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const express = require('express');
const { FundTask, KPLEstablishConnection, KPLFundTask, getTaskStateInfo, KPLCheckProgram } = require('@_koii/create-task-cli');
const { establishConnection, checkProgram } = require('@_koii/create-task-cli');
const {PublicKey, Connection,Keypair} = require('@_koii/web3.js');
const crypto = require('crypto');
const { parse } = require('path');
const axios = require('axios');
import express from 'express';
import { FundTask, KPLEstablishConnection, KPLFundTask, getTaskStateInfo, KPLCheckProgram } from '@_koii/create-task-cli';
import { establishConnection, checkProgram } from '@_koii/create-task-cli';
import { PublicKey, Connection, Keypair } from '@_koii/web3.js';
import crypto from 'crypto';
import { parse } from 'path';
import axios from 'axios';
import dotenv from 'dotenv';

dotenv.config();

const app = express();
const port = 3000;
const SIGNING_SECRET = process.env.SIGNING_SECRET
const funder_keypair = process.env.funder_keypair
const user_id_list = ['U06NM9A2VC1', 'U02QTSK9R3N', 'U02QNL3PPFF']
const port = process.env.PORT || 3000;

const SIGNING_SECRET = process.env.SIGNING_SECRET;
const funder_keypair = process.env.funder_keypair;
const user_id_list = ['U06NM9A2VC1', 'U02QTSK9R3N', 'U02QNL3PPFF'];

app.use(express.raw({ type: 'application/x-www-form-urlencoded' }));

function verifySlackRequest(req) {
const slackSignature = req.headers['x-slack-signature'];
const timestamp = req.headers['x-slack-request-timestamp'];
Expand All @@ -31,7 +38,6 @@ function verifySlackRequest(req) {

// Route to handle funding task
app.post('/fundtask', async (req, res) => {

if (!verifySlackRequest(req)) {
return res.status(400).send('Invalid request signature');
}
Expand All @@ -48,64 +54,58 @@ app.post('/fundtask', async (req, res) => {
const text = parsedBody.text;
const response_url = parsedBody.response_url;
const user_id = parsedBody.user_id;

if (!user_id || !user_id_list.includes(user_id)) {
await axios.post(response_url, {
response_type: "in_channel",
text: 'Sorry, please tag <@U06NM9A2VC1> to add you to the list! '
})
});
return;
}

let parts = text.split(' ').filter(part => part.trim() !== '');
let TASK_ID = parts[0].trim();
let AMOUNT = parts[1].trim();
try{
await generic_fund_task(TASK_ID, AMOUNT)

try {
await generic_fund_task(TASK_ID, AMOUNT);
await axios.post(response_url, {
response_type: "in_channel",
text: `Congrats! <@${user_id}> You funded ${AMOUNT} to task ${TASK_ID} successfully. `
})
}catch(e){
});
} catch(e) {
await axios.post(response_url, {
response_type: "in_channel",
text: `Failed to fund ${AMOUNT} to ${TASK_ID}. ${e}`
})
});
}
});

app.listen(port, () => {
console.log(`App running on port ${port}`);
});


async function generic_fund_task(TASK_ID, AMOUNT){
async function generic_fund_task(TASK_ID, AMOUNT) {
const connection = new Connection("https://testnet.koii.network", "confirmed");

const taskStateJSON = await getTaskStateInfo(
connection,
TASK_ID,
);
);
const stakePotAccount = new PublicKey(taskStateJSON.stake_pot_account, connection);

if (taskStateJSON.token_type) {
const mint_uint8 = Uint8Array.from(taskStateJSON.token_type);

// Create the PublicKey
const mint_publicKey = new PublicKey(mint_uint8);
await fund_a_KPL_task(TASK_ID, AMOUNT, stakePotAccount, connection, mint_publicKey)

}else{

await fund_a_task(TASK_ID, AMOUNT, stakePotAccount, connection)

await fund_a_KPL_task(TASK_ID, AMOUNT, stakePotAccount, connection, mint_publicKey);
} else {
await fund_a_task(TASK_ID, AMOUNT, stakePotAccount, connection);
}
}
async function fund_a_task(TASK_ID, AMOUNT, stakePotAccount,connection){

async function fund_a_task(TASK_ID, AMOUNT, stakePotAccount, connection) {
console.log("Start Funding:");
console.log("Funding task with Id: ", TASK_ID);
console.log("Funding amount: ", AMOUNT);

const payerKeypairString = process.env.funder_keypair;
// Parse the JSON string into an array
const payerKeypairArray = JSON.parse(payerKeypairString);
// Convert the array to a Uint8Array
const payerWallet = Uint8Array.from(payerKeypairArray);
const payerKeypair = Keypair.fromSecretKey(payerWallet);
const taskStateInfoAddress = new PublicKey(TASK_ID);
Expand All @@ -115,23 +115,29 @@ async function fund_a_task(TASK_ID, AMOUNT, stakePotAccount,connection){
// Create-task-cli package setup
await establishConnection(connection);
await checkProgram();
await FundTask(payerKeypair,taskStateInfoAddress,stakePotAccount, amount);
await FundTask(payerKeypair, taskStateInfoAddress, stakePotAccount, amount);
}

async function fund_a_KPL_task(TASK_ID, AMOUNT, stakePotAccount,connection, mint_publicKey){
async function fund_a_KPL_task(TASK_ID, AMOUNT, stakePotAccount, connection, mint_publicKey) {
console.log("Start Funding:");
console.log("Funding task with Id: ", TASK_ID);
console.log("Funding amount: ", AMOUNT);
const payerKeypairString = funder_keypair
// Parse the JSON string into an array

const payerKeypairString = funder_keypair;
const payerKeypairArray = JSON.parse(payerKeypairString);
// Convert the array to a Uint8Array
const payerWallet = Uint8Array.from(payerKeypairArray);
const payerKeypair = Keypair.fromSecretKey(payerWallet);
const taskStateInfoAddress = new PublicKey(TASK_ID);
const amount = parseInt(AMOUNT);

// Create-task-cli package setup
await KPLEstablishConnection(connection);
await KPLCheckProgram();
await KPLFundTask(payerKeypair,taskStateInfoAddress, stakePotAccount, amount, mint_publicKey);
await KPLFundTask(payerKeypair, taskStateInfoAddress, stakePotAccount, amount, mint_publicKey);
}

const server = app.listen(port, () => {
console.log(`App running on port ${port}`);
});

export { app, server };
Loading