Navigation Menu

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 / 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 / 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
// 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"
@vlzhr
vlzhr / stricts-variables.scala
Created May 14, 2021 09:17
RIDE code snippet
func foo() = {
...
strict balanceBefore = wavesBalance(this).regular
strict z = invoke(dapp2,bar,args,[AttachedPayment(unit,100000000)])
strict balanceAfter = wavesBalance(this).regular
if(balanceAfter < balanceBefore) then ... else...
}
@vlzhr
vlzhr / dapp-to-dapp.scala
Created May 14, 2021 09:13
Snippet for RIDE code
strict z = invoke(dapp, func, args,[AttachedPayment(unit,100000000)])
// invoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any