Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicarq committed Sep 5, 2024
1 parent 6ea96d2 commit 9469812
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
23 changes: 18 additions & 5 deletions apps/shinkai-tool-coinbase-get-balance/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder';
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition';
import { Coinbase, CoinbaseOptions } from '@coinbase/coinbase-sdk';
import { Coinbase, CoinbaseOptions, Wallet, Balance as BalanceModel } from '@coinbase/coinbase-sdk';
import { Decimal } from 'decimal.js';

type Config = {
name: string;
Expand All @@ -12,9 +13,12 @@ type Params = {
walletId?: string;
};
type Result = {
data: string;
message: string;
balances: WalletBalances | null;
};

type WalletBalances = { [key: string]: number };

export class Tool extends BaseTool<Config, Params, Result> {
definition: ToolDefinition<Config, Params, Result> = {
id: 'shinkai-tool-coinbase-get-balance',
Expand Down Expand Up @@ -43,9 +47,10 @@ export class Tool extends BaseTool<Config, Params, Result> {
result: {
type: 'object',
properties: {
data: { type: 'string' },
message: { type: 'string' },
balances: { type: 'object', nullable: true },
},
required: ['data'],
required: ['message'],
},
};

Expand All @@ -54,6 +59,7 @@ export class Tool extends BaseTool<Config, Params, Result> {
apiKeyName: this.config.name,
privateKey: this.config.privateKey,
useServerSigner: this.config.useServerSigner === 'true',
debugging: true,
};
const coinbase = new Coinbase(coinbaseOptions);
const user = await coinbase.getDefaultUser();
Expand All @@ -73,9 +79,16 @@ export class Tool extends BaseTool<Config, Params, Result> {
let balances = await wallet.listBalances();
console.log(`Balances: `, balances);

// Convert balances to WalletBalances
const balanceMap: WalletBalances = {};
for (const [currency, amount] of balances) {
balanceMap[currency] = amount.toNumber();
}

return {
data: {
data: `Balances: ${balances.toString()}`,
message: `Balances: ${JSON.stringify(balanceMap)}`,
balances: balanceMap,
},
};
}
Expand Down
8 changes: 4 additions & 4 deletions apps/shinkai-tool-coinbase-get-my-address/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Params = {
walletId?: string;
};
type Result = {
data: string;
address: string;
};

export class Tool extends BaseTool<Config, Params, Result> {
Expand Down Expand Up @@ -42,9 +42,9 @@ export class Tool extends BaseTool<Config, Params, Result> {
result: {
type: 'object',
properties: {
data: { type: 'string' },
address: { type: 'string' },
},
required: ['data'],
required: ['address'],
},
};

Expand Down Expand Up @@ -74,7 +74,7 @@ export class Tool extends BaseTool<Config, Params, Result> {

return {
data: {
data: `Default Address: ${address?.getId()}`,
address: address?.getId() || '',
},
};
}
Expand Down
19 changes: 13 additions & 6 deletions apps/shinkai-tool-coinbase-send-tx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder';
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition';
import { Coinbase, CoinbaseOptions } from '@coinbase/coinbase-sdk';
import { Coinbase, CoinbaseOptions, Transfer } from '@coinbase/coinbase-sdk';

type Config = {
name: string;
Expand All @@ -15,7 +15,9 @@ type Params = {
amount: string;
};
type Result = {
data: string;
transactionHash: string;
transactionLink: string;
status: string;
};

export class Tool extends BaseTool<Config, Params, Result> {
Expand Down Expand Up @@ -49,9 +51,11 @@ export class Tool extends BaseTool<Config, Params, Result> {
result: {
type: 'object',
properties: {
data: { type: 'string' },
transactionHash: { type: 'string' },
transactionLink: { type: 'string' },
status: { type: 'string' },
},
required: ['data'],
required: ['transactionHash', 'transactionLink', 'status'],
},
};

Expand Down Expand Up @@ -137,12 +141,13 @@ export class Tool extends BaseTool<Config, Params, Result> {
const formattedAssetId = params.assetId.toLowerCase();

// Create and send the transfer
let transfer;
let transfer: Transfer;
try {
transfer = await wallet.createTransfer({
amount,
assetId: Coinbase.toAssetId(formattedAssetId),
destination: params.recipient_address,
// gasless: true,
});
console.log(`Transfer successfully completed: `, transfer.toString());
} catch (error) {
Expand All @@ -157,7 +162,9 @@ export class Tool extends BaseTool<Config, Params, Result> {

return {
data: {
data: `Transfer completed successfully: ${transfer.toString()}`,
transactionHash: transfer.getTransactionHash() || '',
transactionLink: transfer.getTransactionLink() || '',
status: transfer.getStatus() || '',
},
};
}
Expand Down

0 comments on commit 9469812

Please sign in to comment.