-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Coinbase Developer Platform - New Wallet Event #18342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 37 additions & 5 deletions
42
components/coinbase_developer_platform/coinbase_developer_platform.app.mjs
This file contains hidden or 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 |
---|---|---|
@@ -1,11 +1,43 @@ | ||
import { | ||
Coinbase, Webhook, | ||
} from "@coinbase/coinbase-sdk"; | ||
|
||
export default { | ||
type: "app", | ||
app: "coinbase_developer_platform", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
walletAddress: { | ||
type: "string", | ||
label: "Address", | ||
description: "The address of the wallet to monitor. Example: `0x8fddcc0c5c993a1968b46787919cc34577d6dc5c`", | ||
}, | ||
networkId: { | ||
type: "string", | ||
label: "Network ID", | ||
description: "The network ID of the wallet to monitor. Example: `base-mainnet`", | ||
async options() { | ||
const networks = Coinbase.networks; | ||
return Object.values(networks); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
configure() { | ||
const apiKeyName = this.$auth.api_key_id; | ||
const privateKey = this.$auth.secret_key; | ||
Coinbase.configure({ | ||
apiKeyName, | ||
privateKey, | ||
}); | ||
}, | ||
listWebhooks() { | ||
return Webhook.list(); | ||
}, | ||
createWebhook(opts) { | ||
return Webhook.create(opts); | ||
}, | ||
deleteWebhook(webhook) { | ||
return webhook.delete(); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
components/coinbase_developer_platform/sources/common/base.mjs
This file contains hidden or 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,29 @@ | ||
import coinbase from "../../coinbase_developer_platform.app.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
coinbase, | ||
db: "$.service.db", | ||
http: "$.interface.http", | ||
}, | ||
methods: { | ||
_getWebhookId() { | ||
return this.db.get("webhookId"); | ||
}, | ||
_setWebhookId(webhookId) { | ||
this.db.set("webhookId", webhookId); | ||
}, | ||
generateMeta() { | ||
throw new ConfigurationError("generateMeta is not implemented"); | ||
}, | ||
}, | ||
async run(event) { | ||
const { body } = event; | ||
if (!body) { | ||
return; | ||
} | ||
const meta = this.generateMeta(body); | ||
this.$emit(body, meta); | ||
}, | ||
}; |
70 changes: 70 additions & 0 deletions
70
components/coinbase_developer_platform/sources/new-wallet-event/new-wallet-event.mjs
This file contains hidden or 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,70 @@ | ||
import common from "../common/base.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
name: "New Wallet Event (Instant)", | ||
key: "coinbase_developer_platform-new-wallet-event", | ||
description: "Emit new event for each new wallet event. [See the documentation](https://docs.cdp.coinbase.com/webhooks/cdp-sdk#external-address-webhook)", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
...common.props, | ||
walletAddress: { | ||
propDefinition: [ | ||
common.props.coinbase, | ||
"walletAddress", | ||
], | ||
}, | ||
networkId: { | ||
propDefinition: [ | ||
common.props.coinbase, | ||
"networkId", | ||
], | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
this.coinbase.configure(); | ||
const webhook = await this.coinbase.createWebhook({ | ||
notificationUri: this.http.endpoint, | ||
eventType: "wallet_activity", | ||
networkId: this.networkId, | ||
eventTypeFilter: { | ||
addresses: [ | ||
this.walletAddress, | ||
], | ||
wallet_id: "", | ||
}, | ||
}); | ||
|
||
if (!webhook?.model?.id) { | ||
throw new ConfigurationError("Failed to create webhook"); | ||
} | ||
|
||
this._setWebhookId(webhook.model.id); | ||
}, | ||
async deactivate() { | ||
this.coinbase.configure(); | ||
const webhookId = this._getWebhookId(); | ||
if (webhookId) { | ||
const { data: webhooks } = await this.coinbase.listWebhooks(); | ||
const webhook = webhooks.find((webhook) => webhook.model.id === webhookId); | ||
await this.coinbase.deleteWebhook(webhook); | ||
} | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
methods: { | ||
...common.methods, | ||
generateMeta(body) { | ||
return { | ||
id: body.transactionHash, | ||
summary: `New ${body.eventType} event`, | ||
ts: Date.parse(body.blockTime), | ||
}; | ||
}, | ||
}, | ||
sampleEmit, | ||
}; |
15 changes: 15 additions & 0 deletions
15
components/coinbase_developer_platform/sources/new-wallet-event/test-event.mjs
This file contains hidden or 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,15 @@ | ||
export default { | ||
"blockHash": "0x351bd04dfe350fca186cd47080220283a75d07018ed251748a4ad19e7f327caf", | ||
"blockNumber": 20305354, | ||
"blockTime": "2024-09-27T21:16:40.000Z", | ||
"contractAddress": "0xab39a8b6801b0b6aa20e9a1953c861ec0a57d175", | ||
"eventType": "erc20_transfer", | ||
"from": "0x10db590ffa5b7bc46cffbd436180e01b6c5c0af6", | ||
"logIndex": "121", | ||
"network": "base-sepolia", | ||
"to": "0x4a9ab171e31daff484c70921f2f5e89a8fe12f59", | ||
"transactionHash": "0x940db3006449456b386397ab42114134d745d2876196226444601670f3e99db8", | ||
"transactionIndex": "19", | ||
"value": "1000000", | ||
"webhookId": "66bd79d0b9c200eae1a43165" | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -8,4 +8,4 @@ export default { | |
console.log(Object.keys(this.$auth)); | ||
}, | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.