Skip to content
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

feat!: refactor api #61

Merged
merged 44 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f3da187
validate /w team
BeroBurny Sep 26, 2024
47afc40
swap `zod` with `superstruct`
BeroBurny Sep 26, 2024
3956863
first case for api refactor
BeroBurny Sep 26, 2024
ce3b88c
move sprinter to separate file
BeroBurny Sep 26, 2024
db2a9cf
refactor
BeroBurny Sep 26, 2024
18f768b
smoll fixes
BeroBurny Sep 30, 2024
b1151a8
sprinter class docs
BeroBurny Sep 30, 2024
c72bc78
add enum :man_shrugging:
BeroBurny Sep 30, 2024
ddd45f2
micro bug fixes
BeroBurny Sep 30, 2024
c61895f
refactor POC to match new SDK
BeroBurny Sep 30, 2024
ed12547
lint
BeroBurny Sep 30, 2024
9c4272d
change sprinter sdk from dependencies to peer dependencies
BeroBurny Sep 30, 2024
2121e83
partially refactor react sdk
BeroBurny Sep 30, 2024
b8656c9
react sdk docs and smool fix
BeroBurny Oct 1, 2024
4d73265
fix yarn.lock
BeroBurny Oct 1, 2024
c84f104
fix ci
BeroBurny Oct 1, 2024
33ef698
fix yarn command
BeroBurny Oct 1, 2024
c5e921d
save
BeroBurny Oct 8, 2024
a7f93e3
save general
BeroBurny Oct 8, 2024
56231ea
refactor `sourceChains` behavior for single hop
BeroBurny Oct 8, 2024
dd1d8c8
sdk docs v1 on new approach
BeroBurny Oct 8, 2024
e46aeed
react docs v1
BeroBurny Oct 8, 2024
7f72af1
Merge branch 'master' into beroburny/api-refactor
BeroBurny Oct 8, 2024
046d431
dirty fix
BeroBurny Oct 8, 2024
a75d753
wtf is that? remove! purger!
BeroBurny Oct 8, 2024
f45864e
prettify category and push overview into index
BeroBurny Oct 9, 2024
eeb6625
fix example response for available tokens
BeroBurny Oct 9, 2024
0589132
fix network list
BeroBurny Oct 10, 2024
2efbfd7
implement remark plugins
BeroBurny Oct 10, 2024
fbe318b
fix `recipient`
BeroBurny Oct 10, 2024
7d69042
implement calldata usages
BeroBurny Oct 10, 2024
b86162e
gas tips
BeroBurny Oct 10, 2024
9acc443
smoll fix
BeroBurny Oct 10, 2024
a4ddc83
refactor gas tip
BeroBurny Oct 14, 2024
bc516e4
implement tabs in bridge and call
BeroBurny Oct 15, 2024
dfad461
ci / cd
BeroBurny Oct 15, 2024
e1fd86c
gas limit
BeroBurny Oct 15, 2024
2566a3c
aggregate
BeroBurny Oct 15, 2024
06a56ac
fix links
BeroBurny Oct 15, 2024
2ca9ae6
breaking changes docs
BeroBurny Oct 16, 2024
33156ae
comments
BeroBurny Oct 18, 2024
edc6911
curl example
BeroBurny Oct 18, 2024
6622bd5
address comments regarding method names
BeroBurny Oct 24, 2024
9b04fb4
fix breaking changes doc
BeroBurny Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix recipient
BeroBurny committed Oct 10, 2024
commit fbe318bb0e94fc7232b62742a82fe4d50e1c7758
2 changes: 2 additions & 0 deletions packages/sdk/src/api.ts
Original file line number Diff line number Diff line change
@@ -182,6 +182,7 @@ export async function getContractCallSolution(
token,
amount,
contractCall,
recipient,
threshold,
whitelistedSourceChains,
}: SingleHopContractSolutionOptions,
@@ -199,6 +200,7 @@ export async function getContractCallSolution(
destination: destinationChain,
destinationContractCall: contractCall,
type: "fungible",
recipient,
threshold,
whitelistedSourceChains,
}),
18 changes: 10 additions & 8 deletions packages/sdk/src/internal/validators.ts
Original file line number Diff line number Diff line change
@@ -37,18 +37,20 @@ const BridgeCoreSchema = object({
sourceChains: optional(array(number())),
});

const BridgeCoreWithRecipientSchema = assign(
BridgeCoreSchema,
object({
recipient: hexString(),
}),
);

const ContractCallCoreSchema = object({
callData: hexString(),
contractAddress: hexString(),
gasLimit: numberLike,
});

const NativeContractCallSchema = assign(
ContractCallCoreSchema,
object({
recipient: hexString(),
}),
);
const NativeContractCallSchema = ContractCallCoreSchema;

const TokenContractCallSchema = assign(
ContractCallCoreSchema,
@@ -62,12 +64,12 @@ const ContractCallSchema = object({
contractCall: union([NativeContractCallSchema, TokenContractCallSchema]),
});

export const SingleHopSchema = BridgeCoreSchema;
export const SingleHopSchema = BridgeCoreWithRecipientSchema;

export const MultiHopSchema = BridgeCoreSchema;

export const SingleHopWithContractSchema = assign(
BridgeCoreSchema,
BridgeCoreWithRecipientSchema,
ContractCallSchema,
);

37 changes: 19 additions & 18 deletions packages/sdk/src/sprinter.ts
Original file line number Diff line number Diff line change
@@ -352,6 +352,7 @@ export class Sprinter {
* - `destinationChain`: The ID of the destination blockchain.
* - `token`: The token symbol (e.g., "ETH", "USDC") to be bridged.
* - `amount`: The amount of tokens to bridge (as a string or number).
* - `recipient` (optional): The address of the recipient of any leftover tokens.
* - `threshold` (optional): The minimum amount threshold required for bridging.
* - `sourceChains` (optional): An array of whitelisted source chain IDs for the transfer.
*
@@ -370,6 +371,7 @@ export class Sprinter {
* destinationChain: 11155111,
* token: "USDC",
* amount: "100000000",
* recipient: "0xRecipientAddress", // Optional recipient of leftover tokens
* };
*
* sprinter.bridge(settings).then(solution => {
@@ -402,24 +404,24 @@ export class Sprinter {
* This method transfers tokens from a source chain to a destination chain and then executes a contract call on the destination chain.
*
* @param {Infer<typeof SingleHopWithContractSchema>} settings - The settings object for defining the bridging and contract call parameters:
* - `account`: The user's wallet address for the transaction.
* - `destinationChain`: The ID of the destination blockchain.
* - `token`: The token symbol (e.g., "ETH", "USDC") to be bridged.
* - `amount`: The amount of tokens to bridge (as a string or number).
* - `contractCall`: Defines the contract call that will be executed on the destination chain:
* - `account` {string}: The user's wallet address for the transaction.
* - `destinationChain` {number}: The ID of the destination blockchain.
* - `token` {string}: The token symbol (e.g., "ETH", "USDC") to be bridged.
* - `amount` {string | number}: The amount of tokens to bridge (in the smallest denomination).
* - `contractCall` {Object}: Defines the contract call that will be executed on the destination chain:
* - For native contract calls (`NativeContractCall`):
* - `callData`: The encoded data to be sent to the contract.
* - `contractAddress`: The address of the contract to call.
* - `gasLimit`: The gas limit for the contract call.
* - `recipient`: The address of the recipient of the call.
* - `callData` {string}: The encoded data to be sent to the contract.
* - `contractAddress` {string}: The address of the contract to call.
* - `gasLimit` {number | string}: The gas limit for the contract call.
* - For token contract calls (`TokenContractCall`):
* - `callData`: The encoded data to be sent to the contract.
* - `contractAddress`: The address of the contract to call.
* - `gasLimit`: The gas limit for the contract call.
* - `outputTokenAddress` (optional): The address of the output token (if different from the input).
* - `approvalAddress` (optional): The address to approve for spending tokens.
* - `sourceChains` (optional): An array of whitelisted source chain IDs for the transfer.
* - `threshold` (optional): The minimum amount threshold required for bridging.
* - `callData` {string}: The encoded data to be sent to the contract.
* - `contractAddress` {string}: The address of the contract to call.
* - `gasLimit` {number | string}: The gas limit for the contract call.
* - `outputTokenAddress` {string} (optional): The address of the output token (if different from the input).
* - `approvalAddress` {string} (optional): The address to approve for spending tokens.
* - `recipient` {string} (optional): The address of the recipient of any leftover tokens.
* - `sourceChains` {Array<number>} (optional): An array of whitelisted source chain IDs for the transfer.
* - `threshold` {number} (optional): The minimum amount threshold required for bridging.
*
* @param {FetchOptions} [options] - Optional configuration for the fetch request, such as custom headers or query parameters.
*
@@ -440,8 +442,8 @@ export class Sprinter {
* callData: "0xabcdef", // encoded contract call data
* contractAddress: "0x1234567890abcdef",
* gasLimit: 21000,
* recipient: "0xRecipientAddress" // for native contract call
* },
* recipient: "0xRecipientAddress", // for sending leftover tokens
* };
*
* sprinter.bridgeAndCall(settings).then(solution => {
@@ -450,7 +452,6 @@ export class Sprinter {
* console.error(error);
* });
* ```
*
*/
public async bridgeAndCall(
settings: Infer<typeof SingleHopWithContractSchema>,
2 changes: 1 addition & 1 deletion packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -54,10 +54,10 @@ export interface ContractCallSolutionOptions {
///
outputTokenAddress?: Address;
approvalAddress?: Address;
recipient?: Address;
}

export interface SingleHopContractSolutionOptions extends SolutionOptions {
recipient?: Address;
contractCall?: ContractCallSolutionOptions;
}