-
Notifications
You must be signed in to change notification settings - Fork 557
Add Bridge.Onramp functions + port old functions #7076
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
54 commits
Select commit
Hold shift + click to select a range
efc4687
[SDK] Feature: Switch buyWithCrypto to Universal Bridge service
gregfromstl 6744d0a
[SDK] Feature: Add Bridge.Transfer module
gregfromstl 77ad035
changeset
gregfromstl 2c33488
Merge branch 'main' into greg/tool-4362-switch-payembed-to-ub-service
gregfromstl 02b1c4a
[SDK] Update Routes endpoint for transaction pay modal
gregfromstl 8112650
changeset
gregfromstl dfe29f0
lint
gregfromstl 421d959
chore: use configured bridge domain
gregfromstl cdaf130
max limit, domains
joaquim-verges 91de2cc
add icon, duration
joaquim-verges 727d0e9
fix approval, minimal status adapter
joaquim-verges abd77ec
refactor: update import for Transfer module in getTransfer.ts
gregfromstl 1b00833
Merge branch 'greg/tool-4506-update-routes-endpoint' of https://githu…
gregfromstl 6eff0e0
[Docs] Stylus dev workflow (#7060)
kumaryash90 ea05f7d
[SDK] Export prepareUserOp and add support for new wallets (#7061)
joaquim-verges 57ecf61
[Vault] default to engine-cloud vault proxy (#7058)
d4mr 05516bd
[Docs] Engine (#7057)
saminacodes 267feda
[DOCS] fix link in contributing.md (#7063)
gap-editor c4a9fac
[Engine] Add FAILED status to execution result and update error handl…
joaquim-verges a7c1257
[Engine] Add all testnets to test transaction options (#7066)
joaquim-verges 378993b
[Docs] Engine Update (#7052)
saminacodes e701530
[SDK] Fix buyWithCrypto false not respected when returning from quote…
joaquim-verges 4bc4caf
[Dashboard] Add pagination to server wallets page (#7070)
joaquim-verges b953056
Version Packages (#7042)
joaquim-verges 72bc53b
[SDK] Update package READMEs with correct naming and documentation li…
joaquim-verges c6af295
Prioritize JWT over service API keys in authentication (#7020)
jnsdls 58ca5f7
chore: Update Accelerate features list (#7053)
arcoraven b128358
Version Packages (#7073)
joaquim-verges 6d8d185
[Dashboard] Remove taint for THIRDWEB_ENGINE_URL (#7074)
joaquim-verges 197d85b
update status endpoint
joaquim-verges 8aa198b
fix 0 balance issue
joaquim-verges 638dddc
lint
joaquim-verges 2e6ad54
Merge remote-tracking branch 'origin' into greg/tool-4506-update-rout…
joaquim-verges 4eeca27
fix
joaquim-verges 8bcecf5
fix test
joaquim-verges f989121
remove tx history, show 0 fees for now
joaquim-verges a2a8723
onramp endpoint wrapper
joaquim-verges c2bbb0d
status
joaquim-verges cec95b0
export
joaquim-verges e89ff31
adapt buyWithFiat legacy function
joaquim-verges 7da5372
Merge remote-tracking branch 'origin/main' into joaquim/onramp
joaquim-verges 2b2b6cc
remove kado, fixes
joaquim-verges a1f5b91
state cleanup
joaquim-verges 1c64203
update status legacy function
joaquim-verges 388eeb9
changeset
joaquim-verges 751746c
lint
joaquim-verges df465f1
remove test
joaquim-verges 696bff4
fix exports
joaquim-verges f3cb4a0
export type
joaquim-verges 3d912bd
more export
joaquim-verges de79cf9
comments
joaquim-verges 11dc870
fix test
joaquim-verges 3545b1a
tsdoc
joaquim-verges d194566
fix test
joaquim-verges 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
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,79 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Added Bridge.Onramp.prepare and Bridge.Onramp.status functions | ||
|
||
## Bridge.Onramp.prepare | ||
|
||
Prepares an onramp transaction, returning a link from the specified provider to onramp to the specified token. | ||
|
||
```typescript | ||
import { Bridge } from "thirdweb"; | ||
import { ethereum } from "thirdweb/chains"; | ||
import { NATIVE_TOKEN_ADDRESS, toWei } from "thirdweb/utils"; | ||
|
||
const preparedOnramp = await Bridge.Onramp.prepare({ | ||
client: thirdwebClient, | ||
onramp: "stripe", | ||
chainId: ethereum.id, | ||
tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
receiver: "0x...", // receiver's address | ||
amount: toWei("10"), // 10 of the destination token | ||
// Optional params: | ||
// sender: "0x...", // sender's address | ||
// onrampTokenAddress: NATIVE_TOKEN_ADDRESS, // token to initially onramp to | ||
// onrampChainId: 1, // chain to initially onramp to | ||
// currency: "USD", | ||
// maxSteps: 2, | ||
// purchaseData: { customId: "123" } | ||
}); | ||
|
||
console.log(preparedOnramp.link); // URL to redirect the user to | ||
console.log(preparedOnramp.currencyAmount); // Price in fiat currency | ||
``` | ||
|
||
## Bridge.Onramp.status | ||
|
||
Retrieves the status of an Onramp session created via Bridge.Onramp.prepare. | ||
|
||
```typescript | ||
import { Bridge } from "thirdweb"; | ||
|
||
const onrampStatus = await Bridge.Onramp.status({ | ||
id: "022218cc-96af-4291-b90c-dadcb47571ec", | ||
client: thirdwebClient, | ||
}); | ||
|
||
// Possible results: | ||
// { | ||
// status: "CREATED", | ||
// transactions: [], | ||
// purchaseData: { | ||
// orderId: "abc-123", | ||
// }, | ||
// } | ||
// | ||
// or | ||
// { | ||
// status: "PENDING", | ||
// transactions: [], | ||
// purchaseData: { | ||
// orderId: "abc-123", | ||
// }, | ||
// } | ||
// | ||
// or | ||
// { | ||
// status: "COMPLETED", | ||
// transactions: [ | ||
// { | ||
// chainId: 1, | ||
// transactionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | ||
// }, | ||
// ], | ||
// purchaseData: { | ||
// orderId: "abc-123", | ||
// }, | ||
// } | ||
``` |
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
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
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ Developers can turn on Test Mode to test both fiat-to-crypto transactions and cr | |
|
||
## Buy With Fiat | ||
|
||
By setting `testMode` to `true` for Buy With Fiat, you can enable test experiences for our underlying providers (Stripe, Kado, and Transak). | ||
By setting `testMode` to `true` for Buy With Fiat, you can enable test experiences for our underlying providers (Coinbase, Stripe, and Transak). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't true at the moment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we'll have to fix that :D pretty important |
||
|
||
<Tabs defaultValue="connectbutton"> | ||
|
||
|
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,118 @@ | ||
import { toWei } from "src/utils/units.js"; | ||
import { describe, expect, it } from "vitest"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import * as Onramp from "./Onramp.js"; | ||
|
||
// Use the same receiver address as other bridge tests | ||
const RECEIVER_ADDRESS = "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709"; | ||
const NATIVE_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; | ||
|
||
/** | ||
* These tests call the real Bridge Onramp API. They are executed only when a | ||
* `TW_SECRET_KEY` environment variable is present, mirroring the behaviour of | ||
* the other bridge tests in this package. | ||
*/ | ||
describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Onramp.prepare", () => { | ||
it("should prepare an onramp successfully", async () => { | ||
const prepared = await Onramp.prepare({ | ||
client: TEST_CLIENT, | ||
onramp: "stripe", | ||
chainId: 1, | ||
tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
receiver: RECEIVER_ADDRESS, | ||
amount: toWei("0.01"), | ||
}); | ||
|
||
expect(prepared).toBeDefined(); | ||
|
||
// The destinationAmount should be a bigint and greater than zero | ||
expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
||
// A redirect link for the user should be provided | ||
expect(prepared.link).toBeDefined(); | ||
expect(typeof prepared.link).toBe("string"); | ||
|
||
// Intent must be present and reference the correct receiver | ||
expect(prepared.intent).toBeDefined(); | ||
expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
RECEIVER_ADDRESS.toLowerCase(), | ||
); | ||
|
||
// Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
expect(Array.isArray(prepared.steps)).toBe(true); | ||
}); | ||
|
||
it("should surface any errors", async () => { | ||
await expect( | ||
Onramp.prepare({ | ||
client: TEST_CLIENT, | ||
onramp: "stripe", | ||
chainId: 444, // Unsupported chain ID | ||
tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
receiver: RECEIVER_ADDRESS, | ||
amount: toWei("0.01"), | ||
}), | ||
).rejects.toThrowError(); | ||
}); | ||
|
||
it("should prepare a Coinbase onramp successfully", async () => { | ||
const prepared = await Onramp.prepare({ | ||
client: TEST_CLIENT, | ||
onramp: "coinbase", | ||
chainId: 1, | ||
tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
receiver: RECEIVER_ADDRESS, | ||
amount: toWei("0.01"), | ||
}); | ||
|
||
expect(prepared).toBeDefined(); | ||
|
||
// The destinationAmount should be a bigint and greater than zero | ||
expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
||
// A redirect link for the user should be provided | ||
expect(prepared.link).toBeDefined(); | ||
expect(typeof prepared.link).toBe("string"); | ||
|
||
// Intent must be present and reference the correct receiver | ||
expect(prepared.intent).toBeDefined(); | ||
expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
RECEIVER_ADDRESS.toLowerCase(), | ||
); | ||
|
||
// Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
expect(Array.isArray(prepared.steps)).toBe(true); | ||
}); | ||
|
||
it("should prepare a Transak onramp successfully", async () => { | ||
const prepared = await Onramp.prepare({ | ||
client: TEST_CLIENT, | ||
onramp: "transak", | ||
chainId: 1, | ||
tokenAddress: NATIVE_TOKEN_ADDRESS, | ||
receiver: RECEIVER_ADDRESS, | ||
amount: toWei("0.01"), | ||
}); | ||
|
||
expect(prepared).toBeDefined(); | ||
|
||
// The destinationAmount should be a bigint and greater than zero | ||
expect(typeof prepared.destinationAmount).toBe("bigint"); | ||
expect(prepared.destinationAmount > 0n).toBe(true); | ||
|
||
// A redirect link for the user should be provided | ||
expect(prepared.link).toBeDefined(); | ||
expect(typeof prepared.link).toBe("string"); | ||
|
||
// Intent must be present and reference the correct receiver | ||
expect(prepared.intent).toBeDefined(); | ||
expect(prepared.intent.receiver.toLowerCase()).toBe( | ||
RECEIVER_ADDRESS.toLowerCase(), | ||
); | ||
|
||
// Steps array should be defined (it may be empty if the provider supports the destination token natively) | ||
expect(Array.isArray(prepared.steps)).toBe(true); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include an optional country param in case calling from the server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw i dont think the ip country detection works, its letting me see stripe stuff which is not available in NZ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it does either and I don't know why