Skip to content

Commit

Permalink
chore: fix action
Browse files Browse the repository at this point in the history
  • Loading branch information
panukettu committed Jun 3, 2024
1 parent 0180f27 commit ff92125
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 19 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: test

on: workflow_dispatch
on: push

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
Expand All @@ -32,3 +29,11 @@ jobs:
run: |
forge test -vvv
id: test
env:
KREDITS_NETWORK: 'arbitrum'
KRESKO_NETWORK: 'arbitrum'
SAFE_NETWORK: 'arbitrum'
SAFE_ADDRESS: '0x266489Bde85ff0dfe1ebF9f0a7e6Fed3a973cEc3'
SAFE_CHAIN_ID: 42161
KRESKO_FORK: 'kresko-fork'
KREDITS_FORK: 'kredits-fork'
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/kresko-lib
19 changes: 19 additions & 0 deletions src/scripts/KreskoScriptFork.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {ClaimEvent} from "kr/core/IKreditsDiamond.sol";
import {ForkBase} from "c/base/ForkBase.s.sol";
import {SwapArgs} from "kr/core/types/Args.sol";
import {IERC20} from "../../lib/forge-std/src/interfaces/IERC20.sol";
import {ICommonConfigFacet} from "kr/core/IKresko.sol";

contract KreskoScriptFork is ForkBase {
using Log for *;
Expand All @@ -23,7 +24,25 @@ contract KreskoScriptFork is ForkBase {
fetchPythAndUpdate();
}

bytes32[] pythFeeds = [bytes32("ETH")];
bytes32[] pythIds = [
bytes32(
0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
)
];
uint256[] staleTimes = [1000000000];
bool[] invertPyth = [false];
bool[] isClosable = [false];
ICommonConfigFacet.PythConfig pythConfig =
ICommonConfigFacet.PythConfig({
pythIds: pythIds,
staleTimes: staleTimes,
invertPyth: invertPyth,
isClosables: isClosable
});

function execAll() public {
broadcastWith(safe);
kresko.setPythFeeds(pythFeeds, pythConfig);
}
}
16 changes: 8 additions & 8 deletions src/scripts/KreskoScriptSafe.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {SafeTx} from "c/safe/SafeTx.s.sol";
import {Utils} from "c/safe/Utils.s.sol";
import {KrBase} from "c/base/KrBase.s.sol";
import {Help, Log} from "kr/utils/Libs.s.sol";
import {Asset} from "kr/core/types/Data.sol";

contract KreskoScriptSafe is KrBase, SafeTx {
using Log for *;
Expand All @@ -18,16 +19,15 @@ contract KreskoScriptSafe is KrBase, SafeTx {
block.chainid.clg("Chain ID");
}

function execAll() public {
_doSomething();
_doSomethingElse();
function changeConfigs() public {
_exec();
}

function _doSomething() internal broadcasted(SAFE_ADDRESS) {
payable(sender).transfer(0.0001 ether);
}
function _exec() internal broadcasted(SAFE_ADDRESS) {
Asset memory kiss = kresko.getAsset(kissAddr);
kiss.depositLimitSCDP = 1_000_000 ether;
kiss.maxDebtMinter = 100_000 ether;

function _doSomethingElse() internal broadcasted(SAFE_ADDRESS) {
payable(sender).transfer(0.0001 ether);
kresko.updateAsset(kissAddr, kiss);
}
}
25 changes: 21 additions & 4 deletions src/test/KreskoScriptSafe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Test, console} from "forge-std/Test.sol";
import {Tested} from "kr/utils/Tested.t.sol";
import {KreskoScriptSafe} from "s/KreskoScriptSafe.s.sol";
import {Help, Log} from "kr/utils/Libs.s.sol";
import {Asset} from "kr/core/types/Data.sol";

contract KreskoScriptSafeTest is KreskoScriptSafe, Tested {
using Log for *;
Expand All @@ -17,12 +18,28 @@ contract KreskoScriptSafeTest is KreskoScriptSafe, Tested {
super.setUp();
safeBalBefore = SAFE_ADDRESS.balance;
accBalBefore = sender.balance;
execAll();
}

function testKreskoScriptSafe() public {
assertLt(SAFE_ADDRESS.balance, safeBalBefore, "safe-bal-not-lt");
assertGt(sender.balance, accBalBefore, "acc-bal-not-gt");
accBalBefore = 0;
Asset memory kiss = kresko.getAsset(kissAddr);
assertEq(
kiss.depositLimitSCDP,
200_000 ether,
"scdp-deposit-limit-before"
);
assertEq(kiss.maxDebtMinter, 60_000 ether, "minter-debt-limit-before");

changeConfigs();
Asset memory kissAfter = kresko.getAsset(kissAddr);
assertEq(
kissAfter.depositLimitSCDP,
1_000_000 ether,
"scdp-deposit-limit-after"
);
assertEq(
kissAfter.maxDebtMinter,
100_000 ether,
"minter-debt-limit-after"
);
}
}
24 changes: 24 additions & 0 deletions src/ts/sse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { tickers } from '@utils/pyth/config'
import { hermes } from '@utils/pyth/hermes'

const response = await fetch(hermes.sse([tickers.ETH, tickers.BTC]))

if (!response.body) throw new Error('No reader')

const reader = response.body.getReader()
const decoder = new TextDecoder()
while (true) {
const { done, value } = await reader.read()
if (done) break
console.log(decoder.decode(value))
}

// import { keccak256 } from 'viem'
// const hasher = new Bun.CryptoHasher('shake256')

// const testValue = '0x1337'
// const resultBun = hasher.update(testValue, 'hex').digest('hex')
// const resultViem = keccak256(testValue)

// console.log('Bun:', resultBun)
// console.log('Viem:', resultViem)
2 changes: 1 addition & 1 deletion utils/pyth/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const HERMES_URLS = ['https://hermes.pyth.network', 'https://hermes.pyth.network']
export const HERMES_URLS = [process.env.PRIVATE_HERMES_EP, 'https://hermes.pyth.network']

export const tickers = {
'1INCH': '0x63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3',
Expand Down
3 changes: 2 additions & 1 deletion utils/pyth/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { HERMES_URLS } from './config'
import { tickers } from './config'
import { type Pyth, formatPrice, isPythID, isPythTicker } from './types'

const hermes = {
export const hermes = {
sse: (ids: Pyth.ID[]) => `${process.env.PRIVATE_HERMES_EP}/v2/updates/price/stream?ids[]=${ids.join('&ids[]=')}`,
pricesV2: (ids: Pyth.ID[]) =>
fetchHermes<Pyth.V2Response>(`/v2/updates/price/latest?ids[]=${ids.join('&ids[]=')}&binary=true`),
}
Expand Down

0 comments on commit ff92125

Please sign in to comment.