import { HDNode } from '@ethersproject/hdnode'; import * as dotenv from 'dotenv'; import { Wallet } from 'ethers'; import { signAuthenticationTypedData } from '../src/lib/ts-ecdsa/signTypedData'; import { getTsRollupSigner } from '../src/lib/ts-rollup/ts-account'; import { asyncEdDSA } from '../src/lib/eddsa'; import { AccountService, AuctionService, AuthService, ConfigService, OpenAPI } from '../src/api/index'; dotenv.config(); const MNEMONIC = process.env.MNEMONIC as string; const CHAIN_ID = Number(process.env.CHAIN_ID) as number; const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS as string; async function main() { await asyncEdDSA; // Ethereum wallet const wallet = getTestAccounts(1)[0]; // TsAccount (EdDSA keypair) const authSinagure = await signAuthenticationTypedData(CHAIN_ID, CONTRACT_ADDRESS, wallet); const tsAccount = getTsRollupSigner(authSinagure); console.log('Ethereum wallet address:', wallet.address); console.log('TsAccount publicKey:', tsAccount.tsPubKey); // Auth api const authSig = await signAuthenticationTypedData(CHAIN_ID, CONTRACT_ADDRESS, wallet); const challenge = await AuthService.authControllerChanllenge(); OpenAPI.TOKEN = challenge.login_token; const authResponse = await AuthService.authControllerLogin({ l1Addr: wallet.address, // ecdsaSig: authSig, eddsaSig: { R8: ['', ''], S: '', }, eddsaPublicKey: { tsPubKeyX: tsAccount.tsPubKey[0].toString(), tsPubKeyY: tsAccount.tsPubKey[1].toString(), }, }); OpenAPI.TOKEN = authResponse; console.log('========== AUTH ===============', { challenge, authResponse, }); // get AccountInfo const accountInfoResponse = await AccountService.tsAccountControllerGetAccountInfo(wallet.address); const accountId = accountInfoResponse.accountId; console.log('========== KeyPair ===============', { accountInfoResponse, tokenLeafs: accountInfoResponse.tokenLeafs, accountId, }); // Get Market Info const configResponse = await ConfigService.configControllerLoadConfig(); console.log('========== CONFIG ===============', { configResponse, }); // Place bet const lendOrderRequest = tsAccount.prepareTxAuctionLend({ senderId: accountId, lendTokenId: '1', lendAmt: '10000000', orderNonce: Math.round(Math.random() * 1000000).toString(), feeAmount: configResponse.auctionLendFee, maturityTime: '1704067199', expiredTime: '1704007199', interest: '1000000', epoch: configResponse.epoch, lendFeeRate: '15000', feeTokenId: '1', defaultMatchedInterest: '10000000', lendMinFeeAmt: '1230000', }); const lendOrderResponse = await AuctionService.tsAuctionControllerLend(lendOrderRequest); console.log('========== lendOrderResponse ===============', { lendOrderResponse, }); } main() .then(() => { console.log('Done'); process.exit(0); }) .catch((err) => { console.error(err); process.exit(1); }); export function getTestAccounts(num: number) { const hdnode = HDNode.fromMnemonic(MNEMONIC); const accounts = Array(); for (let i = 0; i < num; i++) { const node = hdnode.derivePath(`m/44'/60'/0'/0/${i}`); accounts.push(new Wallet(node)); } return accounts; }