Skip to content

Instantly share code, notes, and snippets.

View vlzhr's full-sized avatar

Vladimir vlzhr

View GitHub Profile
# 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"
// 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",
// 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] *
@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 / 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 / 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 / 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)
{-# STDLIB_VERSION 6 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
### System functions
let Scale8 = 100000000
let Scale16 = 10000000000000000
@vlzhr
vlzhr / transfer-USDT.tact
Last active May 15, 2024 16:38
Transfer USDT on Tact
import "@stdlib/deploy";
message(0xf8a7ea5) TokenTransfer {
query_id: Int as uint64;
amount: Int as coins;
sender: Address;
destination: Address?;
response_destination: Address?;
forward_ton_amount: Int as coins;