Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/common-ghosts-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@yieldxyz/sdk": patch
---

feat: update schemas, bump deps
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
API_URL=https://api.yield.xyz/
API_KEY=
MNEMONIC=
YIELD_ID=base-usdc-eusdc-1-0x0a1a3b5f2041f33522c4efc754a7d096f880ee16-4626-vault
ACTION_TYPE=enter
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ dist/
.idea

# Typescipt
*.tsbuildinfo
*.tsbuildinfo

.env
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": false,
"includes": ["**", "!dist/**", "!node_modules/**", "!pnpm-lock.yaml"]
"includes": ["**", "!dist", "!node_modules", "!pnpm-lock.yaml"]
},
"formatter": {
"enabled": true,
Expand Down
104 changes: 104 additions & 0 deletions example/evm-enter-or-exit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { sdk, type TransactionDto } from "@yieldxyz/sdk";
import BigNumber from "bignumber.js";
import { createWalletClient, http } from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { base } from "viem/chains";

const mnemonic = process.env.MNEMONIC;
const apiKey = process.env.API_KEY;
const apiUrl = process.env.API_URL;
const yieldId = process.env.YIELD_ID;
const actionType = process.env.ACTION_TYPE;

if (
!mnemonic ||
!apiKey ||
!apiUrl ||
!yieldId ||
(actionType !== "enter" && actionType !== "exit")
) {
throw new Error("invalid env variables");
}

sdk.configure({ apiKey, baseURL: apiUrl });

const account = mnemonicToAccount(mnemonic);

const client = createWalletClient({
chain: base,
transport: http(),
account,
});

const transactions = await (actionType === "enter"
? sdk.api.enterYield({
yieldId,
address: account.address,
arguments: { amount: BigNumber("0.0001").toString() },
})
: sdk.api.exitYield({
yieldId,
address: account.address,
arguments: { amount: BigNumber("0.0001").toString() },
})
).then((res) =>
res.transactions.filter(
(
tx,
): tx is TransactionDto & {
status: "WAITING_FOR_SIGNATURE";
unsignedTransaction: string;
} =>
(tx.status === "WAITING_FOR_SIGNATURE" || tx.status === "CREATED") &&
!!tx.unsignedTransaction,
),
);

const sendTransactionsResults: {
txHash: string;
explorerUrl: string | null | undefined;
}[] = [];

for (const tx of transactions) {
const parsedTx = JSON.parse(tx.unsignedTransaction);
const preparedTx = await client.prepareTransactionRequest({
to: parsedTx.to,
value: parsedTx.value,
data: parsedTx.data,
maxFeePerGas: parsedTx.maxFeePerGas,
maxPriorityFeePerGas: parsedTx.maxPriorityFeePerGas,
gas: parsedTx.gasLimit,
type: "eip1559",
});

const txHash = await client.sendTransaction(preparedTx);
await sdk.api.submitTransactionHash(tx.id, { hash: txHash });

let txStatusCheckTimes = 0;

while (txStatusCheckTimes < 10) {
await new Promise((resolve) => setTimeout(resolve, 1500));

const txResult = await sdk.api.getTransaction(tx.id);

if (txResult.status === "CONFIRMED") {
break;
}

txStatusCheckTimes++;
}

sendTransactionsResults.push({
txHash,
explorerUrl: `${client.chain.blockExplorers.default.url}/tx/${txHash}`,
});
}

const positions = await sdk.api.getYieldBalances(yieldId, {
address: account.address,
});

console.log({
positions: JSON.stringify(positions, null, 2),
sendTransactionsResults,
});
11 changes: 0 additions & 11 deletions example/index.ts

This file was deleted.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"generate-api": "orval --config ./orval.config.ts",
"prepare": "husky",
"release": "changeset publish",
"version": "changeset version"
"version": "changeset version",
"example:evm-enter-or-exit": "tsx --env-file='.env' example/evm-enter-or-exit.ts"
},
"main": "./dist/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -55,17 +56,19 @@
}
},
"devDependencies": {
"@biomejs/biome": "2.1.0",
"@changesets/cli": "^2.29.5",
"@biomejs/biome": "2.2.0",
"@changesets/cli": "^2.29.6",
"@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.8.1",
"@faker-js/faker": "^9.9.0",
"@rslib/core": "^0.10.5",
"@types/node": "^24.0.10",
"@rslib/core": "^0.12.2",
"@types/node": "^24.3.0",
"bignumber.js": "^9.3.1",
"husky": "^9.1.7",
"msw": "^2.10.3",
"orval": "^7.10.0",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
"msw": "^2.10.5",
"orval": "^7.11.2",
"tsx": "^4.20.4",
"typescript": "^5.9.2",
"viem": "^2.34.0"
}
}
Loading