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
aggregate
BeroBurny committed Oct 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2566a3c77f838119878f9c76b787908d0936e9b2
4 changes: 2 additions & 2 deletions docs/docs/03-sdk/04-methods-reference/_how-to-gas-limit.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import TabItem from '@theme/TabItem';
The following examples demonstrate how to estimate the `gasLimit` parameter required for interacting with a staking smart contract. We provide examples using different web3 libraries: Web3JS, Viem, and Ethers.

:::note
To ensure that the transaction has enough gas, we recommend using the estimated gas limit from the provider, adding 25% as a buffer, and then adding an additional 200,000 units for fail-safe calculations. This ensures the transaction won’t run out of gas, even for complex contract interactions.
To ensure that the transaction has enough gas, we recommend using the estimated gas limit from the provider, adding 25% as a buffer, and then adding an additional 100,000 units for fail-safe calculations. This ensures the transaction won’t run out of gas, even for complex contract interactions.
:::

<details>
@@ -105,7 +105,7 @@ To ensure that the transaction has enough gas, we recommend using the estimated

async function estimateGas() {
const estimatedGas = await stakingContract.methods.stake(100).estimateGas({ from: account });
const gasLimit = Math.floor(estimatedGas * 1.25) + 200000; // Add 25% and 200k for safety
const gasLimit = Math.floor(estimatedGas * 1.25) + 100000; // Add 25% and 100k for safety
console.log('Estimated Gas Limit:', gasLimit);
}

Original file line number Diff line number Diff line change
@@ -18,7 +18,13 @@ This behavior is generally fine for operations like staking or liquidity deposit

## Usage

### Example: Token Transfer with Contract Call and `transferFrom` Approval
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs groupId="call-type" queryString>
<TabItem value="token" label="Token Transfer with Contract Call">

In this example, a token transfer (e.g., `USDC`) is aggregated from multiple source chains, followed by a contract call on the destination chain. You need to provide `outputTokenAddress` and `approvalAddress` to allow the contract to move tokens on behalf of the user.

```typescript
import { Sprinter } from '@chainsafe/sprinter-sdk';
@@ -39,15 +45,19 @@ const settings = {
outputTokenAddress: '0xOutputTokenAddressHere', // Where tokens will be sent
approvalAddress: '0xApprovalAddressHere' // Contract that needs approval to transfer tokens
},
recipient: '0xRecipientAddress', // Optional recipient of leftover tokens
sourceChains: [84532, 1993], // Optional: List of source chains to be considered
};

sprinter.bridgeAggregateBalanceAndCall(settings).then(solution => {
console.log(solution);
});
```
</TabItem>

### Example: Native Token Transfer with Contract Call
<TabItem value="native" label="Native Token Transfer with Contract Call">

In this example, a native token (e.g., `ETH`) is aggregated from multiple source chains, followed by a contract call on the destination chain.

```typescript
const settings = {
@@ -59,15 +69,26 @@ const settings = {
contractAddress: '0xContractAddressHere',
callData: '0xSomeCallData', // Encoded contract interaction data
gasLimit: 21000, // Standard gas limit for ETH transfers
recipient: '0xRecipientAddressHere' // The recipient of the native token transfer
},
recipient: '0xRecipientAddressHere', // The recipient of the native token transfer
sourceChains: [84532, 1993] // Optional: List of source chains to be considered
};

sprinter.bridgeAggregateBalanceAndCall(settings).then(solution => {
console.log(solution);
});
```
</TabItem>
</Tabs>

:::note
You can limit the solution to a specific source chain using the `sourceChains` field. For example, to use only `BaseSepolia` (chain ID `84532`) and another chain, provide it as an array like this:

```typescript
sourceChains: [84532, 1993];
```
If omitted, Sprinter will consider all available source chains.
:::

### Example: Using `fetchOptions`

@@ -89,22 +110,27 @@ sprinter.bridgeAggregateBalanceAndCall(settings, { baseUrl: 'https://custom.api.
- `contractAddress`: The contract address on the destination chain.
- `callData`: The data to interact with the contract, in hex format.
- `gasLimit`: The maximum amount of gas to use for the contract call.
- `recipient`: The recipient address for the native asset transfer.
- **Token Contract Call**:
- `contractAddress`: The contract address on the destination chain.
- `callData`: The data to interact with the contract, in hex format.
- `gasLimit`: The maximum amount of gas to use for the contract call.
- `outputTokenAddress?`: *(Optional)* The token address where tokens will be sent after the contract call.
- `approvalAddress?`: *(Optional)* The contract address that requires approval to transfer tokens (e.g., for `transferFrom`).
- `recipient?`: *(Optional)* The address of the recipient of any leftover tokens.
- `sourceChains?`: *(Optional)* An array of source chain IDs to be considered for aggregation. If omitted, Sprinter will use all available source chains.
- `threshold?`: *(Optional)* The minimum amount of the token to leave on the source chain, in the smallest denomination (useful for avoiding emptying the source chain completely).

- `fetchOptions?`: *(Optional)* An object containing `baseUrl` to override the default API endpoint for this request.

import HowToCallData from "../_how-to-calldata.md"

<HowToCallData />

import GasLimit from "../_how-to-gas-limit.md"

<GasLimit />

<hr />

## Response

Returns a promise that resolves to a `SolutionResponse`.
@@ -138,6 +164,9 @@ import GasTip from "../_gas-tip.md"

<GasTip />

<Tabs groupId="response-type" queryString>
<TabItem value="token" label="Token Transfer with Contract Call Response">

```json
[
{
@@ -161,7 +190,9 @@ import GasTip from "../_gas-tip.md"
"amount": "100000000",
"duration": 60000000000,
"transaction": {
"data": "0x73c45c98000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000540000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000143e101ec02e7a48d16dade204c96bff842e7e251900000000000000000000000000000000000000000000000000000000000000000000000000000000000000023078000000000000000000000000000000000000000000000000000000000000",
"data": "0x73c45c98000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000540000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000143e101ec02e7a48d16dade204c96bff842e7e251900000000000000000000000000000000000000000000000000000000000000000000000000000000000000023078000000000

000000000000000000000000000000000000000000000000000",
"to": "0x9D5C332Ebe0DaE36e07a4eD552Ad4d8c5067A61F",
"from": "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519",
"value": "0x38d7ea4c68000",
@@ -180,12 +211,53 @@ import GasTip from "../_gas-tip.md"
"chainId": 84532
}
]

}
]
```

}
</TabItem>

<TabItem value="native" label="Native Token Transfer with Contract Call Response">

```json
[
{
"sourceChain": 84532,
"destinationChain": 11155111,
"sourceTokenAddress": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"destinationTokenAddress": "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
"senderAddress": "0x3e101ec02e7a48d16dade204c96bff842e7e2519",
"tool": {
"name": "Sygma-Testnet",
"logoURI": "https://scan.buildwithsygma.com/assets/images/logo1.svg"
},
"gasCost": {
"amount": "221055913000",
"amountUSD": 0
},
"fee": {
"amount": "1000000000000000",
"amountUSD": 0
},
"amount": "100000000",
"duration": 60000000000,
"transaction": {
"data": "0x73c45c98000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000540000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000143e101ec02e7a48d16dade204c96bff842e7e251900000000000000000000000000000000000000000000000000000000000000000000000000000000000000023078000000000000000000000000000000000000000000000000000000000000",
"to": "0x9D5C332Ebe0DaE36e07a4eD552Ad4d8c5067A61F",
"from": "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519",
"value": "0x38d7ea4c68000",
"gasPrice": "0xf433d",
"gasLimit": "0x35f48",
"chainId": 84532
},
"approvals": null
}
]
```

</TabItem>
</Tabs>

---

For more details on other methods, check out the [Methods Reference](./methods-reference.md).