import {
TacSdk,
AgnosticProxySDK,
SenderFactory,
Network,
} from "@tonappchain/sdk";
import { TonConnectUI } from "@tonconnect/ui";
import { ethers } from "ethers";
async function executeCompleteStrategy() {
// Initialize TacSDK
const tacSdk = await TacSdk.create({ network: Network.TESTNET });
// Initialize sender
const tonConnectUI = new TonConnectUI({
manifestUrl: "https://example.com/tonconnect-manifest.json",
});
const sender = await SenderFactory.getSender({ tonConnect: tonConnectUI });
const tvmWalletAddress = sender.getSenderAddress();
// Initialize AgnosticProxy SDK
const agnosticSdk = new AgnosticProxySDK(Network.TESTNET);
const agnosticCallParams = agnosticSdk.getAgnosticCallParams();
// Register contract interfaces
agnosticSdk.addContractInterface(UNISWAP_ROUTER, UNISWAP_ROUTER_ABI);
agnosticSdk.addContractInterface(STAKING_CONTRACT, STAKING_ABI);
// Get smart account address
const smartAccountAddress = await tacSdk.getSmartAccountAddressForTvmWallet(
tvmWalletAddress,
agnosticCallParams.evmTargetAddress
);
// Build strategy: USDC → WETH → Stake
const hooks = [];
// Transfer incoming USDC to smart account
hooks.push(
agnosticSdk.createFullBalanceTransferHook(
TOKENS.USDC,
smartAccountAddress,
false
)
);
// Approve USDC for Uniswap
hooks.push(
agnosticSdk.createFullBalanceApproveHook(TOKENS.USDC, UNISWAP_ROUTER, true)
);
// Swap USDC to WETH
hooks.push(
agnosticSdk.createCustomHook(
UNISWAP_ROUTER,
"swapExactTokensForTokens",
[
ethers.parseUnits("2000", 6), // 2000 USDC
ethers.parseEther("1"), // min 1 WETH
[TOKENS.USDC, TOKENS.WETH],
smartAccountAddress,
Math.floor(Date.now() / 1000) + 3600,
],
{ isFromSAPerspective: true }
)
);
// Approve WETH for staking
hooks.push(
agnosticSdk.createFullBalanceApproveHook(
TOKENS.WETH,
STAKING_CONTRACT,
true
)
);
// Stake WETH with dynamic amount
const replacement = agnosticSdk.createAmountReplacement(
0,
TOKENS.WETH,
smartAccountAddress
);
hooks.push(
agnosticSdk.createCustomHook(
STAKING_CONTRACT,
"stake",
[0n], // Will be replaced with actual WETH balance
{
dynamicReplacements: [replacement],
isFromSAPerspective: true,
}
)
);
// Build ZapCall
const zapCall = agnosticSdk.buildZapCall(
hooks,
[TOKENS.STAKE_SHARE_TOKEN], // Bridge tokens after operation
[] // No NFTs to bridge
);
// Visualize the strategy
console.log("📋 Strategy Visualization:");
agnosticSdk.visualizeZapCall(zapCall);
// Get analytics
const breakdown = agnosticSdk.getZapCallBreakdown(zapCall);
console.log("\n📈 Strategy Analytics:");
console.log(` Total Operations: ${breakdown.totalHooks}`);
console.log(` Estimated Gas: ${breakdown.gasEstimate.toLocaleString()}`);
console.log(` Encoded Size: ${breakdown.encodedSize} bytes`);
// Encode for transaction
const encodedCall = agnosticSdk.encodeZapCall(zapCall);
// Execute via TacSDK
const evmProxyMsg = {
evmTargetAddress: agnosticCallParams.evmTargetAddress,
methodName: agnosticCallParams.methodName,
encodedParameters: encodedCall,
};
const assets = [
{
address: USDCTvmAddress,
amount: 2000,
},
];
await tacSdk.sendCrossChainTransaction(evmProxyMsg, sender, assets);
}