UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

86 lines 3.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WASM_PRECOMPILE_ABI = exports.WASM_PRECOMPILE_ADDRESS = void 0; exports.seiBridge = seiBridge; const viem_1 = require("viem"); const ethers_1 = require("ethers"); exports.WASM_PRECOMPILE_ADDRESS = '0x0000000000000000000000000000000000001002'; exports.WASM_PRECOMPILE_ABI = [ { inputs: [ { internalType: 'string', name: 'contractAddress', type: 'string' }, { internalType: 'bytes', name: 'msg', type: 'bytes' }, { internalType: 'bytes', name: 'coins', type: 'bytes' } ], name: 'execute', outputs: [{ internalType: 'bytes', name: 'response', type: 'bytes' }], stateMutability: 'payable', type: 'function' }, { inputs: [ { components: [ { internalType: 'string', name: 'contractAddress', type: 'string' }, { internalType: 'bytes', name: 'msg', type: 'bytes' }, { internalType: 'bytes', name: 'coins', type: 'bytes' } ], internalType: 'struct IWasmd.ExecuteMsg[]', name: 'executeMsgs', type: 'tuple[]' } ], name: 'execute_batch', outputs: [{ internalType: 'bytes[]', name: 'responses', type: 'bytes[]' }], stateMutability: 'payable', type: 'function' }, { inputs: [ { internalType: 'uint64', name: 'codeID', type: 'uint64' }, { internalType: 'string', name: 'admin', type: 'string' }, { internalType: 'bytes', name: 'msg', type: 'bytes' }, { internalType: 'string', name: 'label', type: 'string' }, { internalType: 'bytes', name: 'coins', type: 'bytes' } ], name: 'instantiate', outputs: [ { internalType: 'string', name: 'contractAddr', type: 'string' }, { internalType: 'bytes', name: 'data', type: 'bytes' } ], stateMutability: 'payable', type: 'function' }, { inputs: [ { internalType: 'string', name: 'contractAddress', type: 'string' }, { internalType: 'bytes', name: 'req', type: 'bytes' } ], name: 'query', outputs: [{ internalType: 'bytes', name: 'response', type: 'bytes' }], stateMutability: 'view', type: 'function' } ]; async function seiBridge({ agent, executeMsg, fundsMsg, chainConfig, amount, onSubmitTx, }) { const encodedExecuteMsg = (0, viem_1.toHex)(JSON.stringify(executeMsg)); const encodedFundsMsg = fundsMsg ? (0, viem_1.toHex)(JSON.stringify(fundsMsg)) : (0, viem_1.toHex)(JSON.stringify([])); // Initialize provider using the chain's EVM RPC URL const provider = new ethers_1.ethers.providers.JsonRpcProvider({ url: chainConfig.evmRpcUrl, skipFetchSetup: true }); const privateKey = process.env.SEI_PRIVATE_KEY; let signer = new ethers_1.ethers.Wallet(privateKey, provider); // Create a contract instance const contractInterface = new ethers_1.ethers.utils.Interface(exports.WASM_PRECOMPILE_ABI); const contract = new ethers_1.ethers.Contract(exports.WASM_PRECOMPILE_ADDRESS, contractInterface, signer); // Call the execute function const tx = await contract.execute(chainConfig.contractAddress, encodedExecuteMsg, encodedFundsMsg, { value: amount ? ethers_1.ethers.utils.parseEther(amount) : undefined }); const receipt = await tx.wait(); const hash = receipt.transactionHash; if (onSubmitTx) { onSubmitTx(hash); } return hash; } //# sourceMappingURL=useSeiBridge.js.map