Skip to content

Instantly share code, notes, and snippets.

View vlzhr's full-sized avatar

Vladimir vlzhr

View GitHub Profile
{-# STDLIB_VERSION 6 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
### System functions
let Scale8 = 100000000
let Scale16 = 10000000000000000
@vlzhr
vlzhr / pretty_apy.py
Created December 25, 2023 12:13
Get pretty number for APY
def prettify_apr(n):
return prettify_number(n * 100) + "%"
def get_pretty_apy(apr):
apy = (1 + apr / 365) ** 365 - 1
return prettify_apr(apy)
@vlzhr
vlzhr / nft-issue.ride
Last active July 25, 2023 18:42
Issue NFT on Waves with Puzzle SDK
# permissionless issue NFT on Waves using puzzlemarket.org SDK
# run this with your Ride code
let nftCreationAddress = Address(base58'3PFQjjDMiZKQZdu5JqTHD7HwgSXyp9Rw9By')
let nftName = "Test NFT" # up to 16 symbols
let nftDescription = "A very rare NFT"
let nftImageLink = "https://ipfs.io/ipfs/bafybeidwsupz24ozr244breub5obhl5dxh22xr3wu7xumm4mlf7tgmocvi/display.png"
let collectionName = "artefacts" # set "" to use default collection name
@vlzhr
vlzhr / puzzle-lend-apy.js
Created July 13, 2023 09:20
Puzzle Lend APY
// calc interest
const supplyInterest = interests[index].times(UR).times(0.8);
// calc supply APY (i = interest)
const calcApy = (i: BN) => {
if (!i || i.isNaN()) return BN.ZERO;
@vlzhr
vlzhr / use-aggregator.ride
Created January 15, 2023 14:01
Calling Puzzle Aggregator from Ride script
# given code shows how you can invoke Puzzle Aggregator on-chain
# aggregator allows to exchange any token to any supported by PuzzleSwap.org
# you can modify any of these 4 parameters
let asset0Bytes = unit # asset you pay
let asset1Str = "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" # asset you want to receive
let amountToExchange = 1000000
let recipientStr = this.toString()
@vlzhr
vlzhr / index.html
Created February 10, 2020 12:14
certificado example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>notpaper</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main">
@vlzhr
vlzhr / check.js
Created February 10, 2020 11:59
certificado example
function checkData() {
const text = document.querySelector(".data").value.split("\n")[0];
const certificateId = text.split(" ")[0];
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://testnodes.wavesnodes.com/addresses/data/3N6EmqqQ1pZderX8sNMrfVuEo85ocPoqs2M/"+certificateId);
xhr.onload = function() {
const doesExist = JSON.parse(xhr.response).value === text;
document.querySelector(".result").innerHTML = doesExist ? "<span style='color: green'><strong>certificado</strong> exists</span>" : "<span style='color: red'><strong>certificado</strong> does not exist</span>";
return doesExist;
// calculate amountOut for puzzle swap
// coef = 0.98 (excludes fee)
calculateAmountOut(coef: number) {
const tokenOut = this.state.tokenOut
const tokenIn = this.getTokenIn();
const BalanceIn = this.state.data.get("global_"+[this.poolData.tokenIds[tokenIn]]+"_balance")
const BalanceOut = this.state.data.get("global_"+[this.poolData.tokenIds[tokenOut]]+"_balance")
const amountOut = BalanceOut / this.poolData.tokenDecimals[tokenOut] *
// to invoke puzzle swap you will need to broadcast this transaction
// TODO: replace poolAddress (for example "3PPRHHF9JKvDLkAc3aHD3Kd5tRZp1CoqAJa")
// TODO: replace assetInId and assetOutId (for example "4kwKSf4Bx2Wq8YxKnVZBhcEHyXzEtJ2pw7ixfJgirwf2" and "54UszKAj3MtYmkdRCqSXAcaQLaVALBy7CCrVkfmfzhxR")
// TODO: set minToReceive if you want to avoid slippage risk
.invoke({
dApp: "poolAddress",
fee: 500000,
payment: {
assetId: "assetInId",
# use this JSON to swap EGGs with ledger
# replace "amount": 100, with your amount of EGGlets (1 EGG = 100, 1.01 EGG = 101)
{
"type": 16,
"version": 2,
"dApp": "3PJQUUiJdvz9etUKED9ju7o7VrcNMtnkXBU",
"call": {
"args": [],
"function": "swapEgg"