-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support aptos * remove unused and fix linting
- Loading branch information
Showing
12 changed files
with
520 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { parseUnits } from "viem"; | ||
import { z } from "zod"; | ||
import type { Plugin } from "../plugins"; | ||
import type { AptosWalletClient } from "../wallets"; | ||
|
||
export function sendAPT(): Plugin<AptosWalletClient> { | ||
return { | ||
name: "send_apt", | ||
supportsSmartWallets: () => true, | ||
supportsChain: (chain) => chain.type === "aptos", | ||
getTools: async (walletClient: AptosWalletClient) => { | ||
return [ | ||
{ | ||
name: "send_apt", | ||
description: "This {{tool}} sends APT to an address.", | ||
parameters: sendAPTParametersSchema, | ||
method: (parameters: z.infer<typeof sendAPTParametersSchema>) => | ||
sendAPTMethod(walletClient, parameters), | ||
}, | ||
]; | ||
}, | ||
}; | ||
} | ||
|
||
const sendAPTParametersSchema = z.object({ | ||
to: z.string().describe("The address to send APT to"), | ||
amount: z.string().describe("The amount of APT to send"), | ||
}); | ||
|
||
async function sendAPTMethod( | ||
walletClient: AptosWalletClient, | ||
parameters: z.infer<typeof sendAPTParametersSchema>, | ||
): Promise<string> { | ||
try { | ||
const { to, amount } = parameters; | ||
const octas = parseUnits(amount, 8); | ||
|
||
const tx = await walletClient.sendTransaction({ | ||
transactionData: { | ||
function: "0x1::coin::transfer", | ||
functionArguments: [to, octas], | ||
typeArguments: ["0x1::aptos_coin::AptosCoin"], | ||
}, | ||
}); | ||
return tx.hash; | ||
} catch (error) { | ||
throw new Error(`Failed to send SOL: ${error}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
Aptos, | ||
type InputGenerateTransactionPayloadData, | ||
type InputViewFunctionData, | ||
type LedgerVersionArg, | ||
} from "@aptos-labs/ts-sdk"; | ||
import type { WalletClient } from "./core"; | ||
|
||
export function isAptosWalletClient(wallet: WalletClient): wallet is AptosWalletClient { | ||
return wallet.getChain().type === "aptos"; | ||
} | ||
|
||
export type AptosTransaction = { | ||
transactionData: InputGenerateTransactionPayloadData; | ||
}; | ||
|
||
export type AptosReadRequest = { | ||
viewFunctionData: InputViewFunctionData; | ||
ledgerVersionArg?: LedgerVersionArg; | ||
}; | ||
|
||
export type AptosReadResult = { | ||
value: unknown; | ||
}; | ||
|
||
export type AptosTransactionResult = { | ||
hash: string; | ||
}; | ||
|
||
export interface AptosWalletClient extends WalletClient { | ||
sendTransaction: (transaction: AptosTransaction) => Promise<AptosTransactionResult>; | ||
read: (request: AptosReadRequest) => Promise<AptosReadResult>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Goat Wallet Aptos 🐐 - TypeScript | ||
|
||
## Installation | ||
|
||
``` | ||
npm install @goat-sdk/wallet-aptos | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { | ||
Account, | ||
Aptos, | ||
AptosConfig, | ||
Ed25519PrivateKey, | ||
Network, | ||
} from "@aptos-labs/ts-sdk"; | ||
|
||
const aptosClient = new Aptos( | ||
new AptosConfig({ | ||
network: Network.TESTNET, | ||
}) | ||
); | ||
|
||
const aptosPrivateKey = process.env.APTOS_PRIVATE_KEY; | ||
const aptosAccount = Account.fromPrivateKey({ | ||
privateKey: new Ed25519PrivateKey(aptosPrivateKey), | ||
}); | ||
|
||
const tools = await getOnChainTools({ | ||
wallet: aptos({ | ||
aptosClient, | ||
aptosAccount, | ||
}), | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@goat-sdk/wallet-aptos", | ||
"version": "0.1.7", | ||
"sideEffects": false, | ||
"files": ["dist/**/*", "README.md", "package.json"], | ||
"scripts": { | ||
"build": "tsup", | ||
"clean": "rm -rf dist", | ||
"test": "vitest run --passWithNoTests" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"@aptos-labs/ts-sdk": "^1.33.1", | ||
"bs58": "^6.0.0", | ||
"tweetnacl": "^1.0.3" | ||
}, | ||
"peerDependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"@aptos-labs/ts-sdk": "^1.33.1" | ||
}, | ||
"homepage": "https://ohmygoat.dev", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/goat-sdk/goat.git" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/goat-sdk/goat/issues" | ||
}, | ||
"keywords": ["ai", "agents", "web3"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { AptosReadRequest, AptosTransaction, AptosWalletClient } from "@goat-sdk/core"; | ||
|
||
import type { Account, Aptos } from "@aptos-labs/ts-sdk"; | ||
|
||
export type AptosWalletOptions = { | ||
aptosAccount: Account; | ||
aptosClient: Aptos; | ||
}; | ||
|
||
export function aptos({ aptosAccount, aptosClient }: AptosWalletOptions): AptosWalletClient { | ||
return { | ||
getAddress: () => aptosAccount.accountAddress.toStringLong(), | ||
getChain() { | ||
return { | ||
type: "aptos", | ||
}; | ||
}, | ||
async signMessage(message: string) { | ||
const signature = aptosAccount.sign(message).toString(); | ||
return { | ||
signature, | ||
}; | ||
}, | ||
async sendTransaction({ transactionData }: AptosTransaction) { | ||
const transaction = await aptosClient.transaction.build.simple({ | ||
sender: aptosAccount.accountAddress, | ||
data: transactionData, | ||
}); | ||
const response = await aptosClient | ||
.signAndSubmitTransaction({ | ||
signer: aptosAccount, | ||
transaction, | ||
}) | ||
.then((tx) => aptosClient.waitForTransaction({ transactionHash: tx.hash })); | ||
return { | ||
hash: response.hash, | ||
}; | ||
}, | ||
async read({ viewFunctionData, ledgerVersionArg }: AptosReadRequest) { | ||
const value = await aptosClient.view({ | ||
payload: viewFunctionData, | ||
options: ledgerVersionArg, | ||
}); | ||
return { | ||
value, | ||
}; | ||
}, | ||
async balanceOf(address: string) { | ||
const balance = await aptosClient.getAccountAPTAmount({ | ||
accountAddress: address, | ||
}); | ||
return { | ||
decimals: 8, | ||
symbol: "APT", | ||
name: "Aptos", | ||
value: BigInt(balance), | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "../../../tsconfig.base.json", | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineConfig } from "tsup"; | ||
import { treeShakableConfig } from "../../../tsup.config.base"; | ||
|
||
export default defineConfig({ | ||
...treeShakableConfig, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"extends": ["//"], | ||
"tasks": { | ||
"build": { | ||
"inputs": ["src/**", "tsup.config.ts", "!./**/*.test.{ts,tsx}", "tsconfig.json"], | ||
"dependsOn": ["^build"], | ||
"outputs": ["dist/**"] | ||
} | ||
} | ||
} |
Oops, something went wrong.