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
10 changes: 9 additions & 1 deletion examples/create-payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* - Fetch payout details and show the associated queue operation for follow-up signing/execution flows.
*/
import 'dotenv/config';
import { instanceOfPayoutPayload } from '../generated-contracts';
import { DefiClient } from '../src';
import { parseChainId, requireEnvVars, runMain } from './utils';

Expand Down Expand Up @@ -57,8 +58,15 @@ runMain(async () => {
})),
);

// TODO: Fetch queue by id
const queue = await client.getDeploymentQueue({ pageSize: 100 });
const operation = queue.items.find((item) => item.operationType === 'PAYOUT' && item.payload?.payoutId === payout.id);
const operation = queue.items.find(
(item) =>
item.operationType === 'PAYOUT' &&
item.payload != null &&
instanceOfPayoutPayload(item.payload) &&
item.payload.payoutId === payout.id,
);
if (!operation) {
throw new Error(`Payout operation for ${payout.id} not found in queue (queue size ${queue.items.length}).`);
}
Expand Down
35 changes: 33 additions & 2 deletions examples/evm-full-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
zeroAddress,
} from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { instanceOfPayoutPayload } from '../generated-contracts';
import {
AssetSortField,
AssetSortOrder,
Expand All @@ -43,6 +44,7 @@ import {
FiatCurrency,
MultisigBlockchainClient,
type QueueOperation,
QueueOperationStatus,
type Transaction,
TransactionOperationType,
TransactionStatus,
Expand Down Expand Up @@ -228,6 +230,29 @@ runMain(async () => {
// ─── Step 5: Payout ───────────────────────────────────────────────────────────
console.log('\n═══ Step 5: Create payout ═══');

const queueBefore = await client.getDeploymentQueue({
statuses: [QueueOperationStatus.Pending, QueueOperationStatus.Ready],
pageSize: 100,
});
if (queueBefore.items.length > 0) {
console.log(
`Found ${queueBefore.items.length} pending/ready queue operation(s); deleting before creating payout...`,
);
const deletedIds = await client.deleteAllQueueOperations();
console.log(`Deleted ${deletedIds.length} operation(s).`);

const queueAfter = await client.getDeploymentQueue({
statuses: [QueueOperationStatus.Pending, QueueOperationStatus.Ready],
pageSize: 100,
});
if (queueAfter.items.length > 0) {
const leftover = queueAfter.items.map((op) => `${op.id} (${op.operationType}, ${op.status})`).join(', ');
throw new Error(
`Queue still has ${queueAfter.items.length} operation(s) after cleanup — resolve them manually before continuing: ${leftover}`,
);
}
}

const payout = await client.createPayout({
currencyId: nativeCurrency.id,
amount: PAYOUT_AMOUNT,
Expand All @@ -248,7 +273,13 @@ runMain(async () => {
'payout queue operation',
async () => {
const queue = await client.getDeploymentQueue({ pageSize: 100 });
const op = queue.items.find((item) => item.operationType === 'PAYOUT' && item.payload?.payoutId === payout.id);
const op = queue.items.find(
(item) =>
item.operationType === 'PAYOUT' &&
item.payload != null &&
instanceOfPayoutPayload(item.payload) &&
item.payload.payoutId === payout.id,
);
return op ?? null;
},
pollInterval,
Expand Down Expand Up @@ -297,7 +328,7 @@ runMain(async () => {
const operationsToExecute = await poll<QueueOperation[]>(
'executable operation',
async () => {
const queue = await client.getDeploymentQueue({ statuses: ['READY'], pageSize: 100 });
const queue = await client.getDeploymentQueue({ statuses: [QueueOperationStatus.Ready], pageSize: 100 });

const payoutReady = queue.items.some((item) => item.id === payoutOperation.id);
if (!payoutReady) return null;
Expand Down
4 changes: 2 additions & 2 deletions examples/queue-execute-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import 'dotenv/config';
import { createPublicClient, createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { DefiClient, MultisigBlockchainClient, type QueueOperation } from '../src';
import { DefiClient, MultisigBlockchainClient, type QueueOperation, QueueOperationStatus } from '../src';
import { getEvmChainById } from '../src/blockchain/get-chain';
import { normalizePrivateKey, parseChainId, requireEnvVars, runMain } from './utils';

Expand All @@ -22,7 +22,7 @@ runMain(async () => {
const accountDetails = await client.getAccount();
await client.selectChain(chainId);

const queue = await client.getDeploymentQueue({ statuses: ['READY'], pageSize: 50 });
const queue = await client.getDeploymentQueue({ statuses: [QueueOperationStatus.Ready], pageSize: 50 });
const operationsToExecute: QueueOperation[] = [];

let currentNonce = Number(queue.nextExecutableNonce);
Expand Down
9 changes: 8 additions & 1 deletion examples/tron-create-payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* - Show associated queue operation for follow-up signing/execution.
*/
import 'dotenv/config';
import { instanceOfPayoutPayload } from '../generated-contracts';
import { DefiClient } from '../src';
import { parseChainId, requireEnvVars, runMain } from './utils';

Expand Down Expand Up @@ -44,7 +45,13 @@ runMain(async () => {
});

const queue = await client.getDeploymentQueue({ pageSize: 100 });
const operation = queue.items.find((item) => item.operationType === 'PAYOUT' && item.payload?.payoutId === payout.id);
const operation = queue.items.find(
(item) =>
item.operationType === 'PAYOUT' &&
item.payload != null &&
instanceOfPayoutPayload(item.payload) &&
item.payload.payoutId === payout.id,
);
if (!operation) {
throw new Error(`Payout operation for ${payout.id} not found in queue.`);
}
Expand Down
12 changes: 10 additions & 2 deletions examples/tron-full-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
*/
import 'dotenv/config';
import { TronWeb } from 'tronweb';
import { instanceOfPayoutPayload } from '../generated-contracts';
import {
AssetSortField,
AssetSortOrder,
type ClaimItem,
DefiClient,
FiatCurrency,
type QueueOperation,
QueueOperationStatus,
TRON_ZERO_ADDRESS,
type Transaction,
TransactionOperationType,
Expand Down Expand Up @@ -259,7 +261,13 @@ runMain(async () => {
'payout queue operation',
async () => {
const queue = await client.getDeploymentQueue({ pageSize: 100 });
const op = queue.items.find((item) => item.operationType === 'PAYOUT' && item.payload?.payoutId === payout.id);
const op = queue.items.find(
(item) =>
item.operationType === 'PAYOUT' &&
item.payload != null &&
instanceOfPayoutPayload(item.payload) &&
item.payload.payoutId === payout.id,
);
return op ?? null;
},
pollInterval,
Expand Down Expand Up @@ -306,7 +314,7 @@ runMain(async () => {
const operationsToExecute = await poll<QueueOperation[]>(
'executable operation',
async () => {
const queue = await client.getDeploymentQueue({ statuses: ['READY'], pageSize: 100 });
const queue = await client.getDeploymentQueue({ statuses: [QueueOperationStatus.Ready], pageSize: 100 });

const payoutReady = queue.items.some((item) => item.id === payoutOperation.id);
if (!payoutReady) return null;
Expand Down
10 changes: 8 additions & 2 deletions examples/tron-queue-execute-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/
import 'dotenv/config';
import { TronWeb } from 'tronweb';
import { DefiClient, type QueueOperation, type TronAddress, TronMultisigBlockchainClient } from '../src';
import {
DefiClient,
type QueueOperation,
QueueOperationStatus,
type TronAddress,
TronMultisigBlockchainClient,
} from '../src';
import { DEFAULT_FEE_LIMIT, parseChainId, requireEnvVars, runMain } from './utils';

const requiredEnv = ['API_BASE_URL', 'API_KEY', 'CHAIN_ID', 'RPC_URL', 'WALLET_PRIVATE_KEY'] as const;
Expand All @@ -19,7 +25,7 @@ runMain(async () => {
const accountDetails = await client.getAccount();
await client.selectChain(chainId);

const queue = await client.getDeploymentQueue({ statuses: ['READY'], pageSize: 50 });
const queue = await client.getDeploymentQueue({ statuses: [QueueOperationStatus.Ready], pageSize: 50 });
const operationsToExecute: QueueOperation[] = [];

let currentNonce = Number(queue.nextExecutableNonce);
Expand Down
17 changes: 9 additions & 8 deletions generated-contracts/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.openapi-generator-ignore
apis/accounts-api.ts
apis/callbacks-api.ts
apis/claims-api.ts
apis/currencies-api.ts
apis/index.ts
Expand All @@ -19,7 +18,6 @@ models/asset-balance-short-response-dto.ts
models/asset-balances-response-dto.ts
models/balance-summary-response-dto.ts
models/call-dto.ts
models/callback.ts
models/claim-item-dto.ts
models/claims-response-dto.ts
models/create-invoice-dto.ts
Expand All @@ -28,33 +26,36 @@ models/create-payout-dto.ts
models/create-reject-operation-dto.ts
models/currencies-controller-find-all-v1-is-native-parameter.ts
models/currency-response-dto.ts
models/dapp-transaction-payload.ts
models/deployment-params-response-dto.ts
models/deployment-queue-response-dto.ts
models/get-callbacks-response-dto.ts
models/index.ts
models/invoice-details-dto.ts
models/invoice-response-dto.ts
models/invoices-response-dto.ts
models/multisig-config-change-payload.ts
models/network-response-dto.ts
models/networks-response-dto.ts
models/nonce-info-response-dto.ts
models/operation-signature-dto.ts
models/payout-detail-response-dto.ts
models/payout-list-response-dto.ts
models/payout-payload.ts
models/payout-response-dto.ts
models/queue-operation-response-dto-dapp-metadata.ts
models/queue-operation-response-dto-payload.ts
models/queue-operation-response-dto.ts
models/resend-callbacks-body-dto.ts
models/resend-callbacks-response-dto.ts
models/signature-response-dto.ts
models/smart-contract-version-response-dto.ts
models/submit-signature-dto.ts
models/transaction-dapp-metadata.ts
models/transaction-details-dto.ts
models/transaction-invoice-response-dto.ts
models/transaction-list-response-dto-items-inner-calls-inner.ts
models/transaction-list-response-dto-items-inner-invoice.ts
models/transaction-list-response-dto-items-inner.ts
models/transaction-list-response-dto.ts
models/transaction-response-dto.ts
models/transactions-controller-get-transactions-v1-currency-is-scam-parameter.ts
models/transactions-controller-get-transactions-v1-currency-is-verified-parameter.ts
models/transactions-controller-get-transactions-v1-is-claimed-parameter.ts
models/universal-address.ts
models/update-account-dto.ts
models/update-invoice-dto.ts
Expand Down
2 changes: 1 addition & 1 deletion generated-contracts/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.16.0
7.22.0
Loading
Loading