Skip to content

Commit

Permalink
add EssentialWeb3Transaction; fix tronweb with backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKozAllB committed Jan 14, 2025
1 parent 9fe61fa commit 812996f
Show file tree
Hide file tree
Showing 16 changed files with 6,911 additions and 5,037 deletions.
843 changes: 738 additions & 105 deletions examples/pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FeePaymentMethod,
Messenger,
nodeRpcUrlsDefault,
RawTronTransaction,
} from "@allbridge/bridge-core-sdk";
import { getEnvVar } from "../../../utils/env";
import { ensure } from "../../../utils/utils";
Expand Down Expand Up @@ -32,10 +33,10 @@ const main = async () => {
//check if sending tokens already approved
if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amountToSendFloat }))) {
// authorize the bridge to transfer tokens from sender's address
const rawTransactionApprove = await sdk.bridge.rawTxBuilder.approve({
const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({
token: sourceToken,
owner: fromAddress,
});
})) as RawTronTransaction;
const approveReceipt = await sendTrxRawTransaction(rawTransactionApprove);
console.log("Approve transaction receipt", JSON.stringify(approveReceipt, null, 2));
}
Expand All @@ -60,7 +61,7 @@ const main = async () => {
gasFeePaymentMethod: FeePaymentMethod.WITH_STABLECOIN,
fee: gasFeeAmount.int,
};
const rawTransactionTransfer = await sdk.bridge.rawTxBuilder.send(params);
const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send(params)) as RawTronTransaction;

const transferReceipt = await sendTrxRawTransaction(rawTransactionTransfer);
console.log("Transfer tokens transaction receipt:", transferReceipt);
Expand Down
16 changes: 11 additions & 5 deletions examples/src/examples/bridge/trx/trx-build-send-tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AllbridgeCoreSdk, ChainSymbol, Messenger, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk";
import {
AllbridgeCoreSdk,
ChainSymbol,
Messenger,
nodeRpcUrlsDefault,
RawTronTransaction,
} from "@allbridge/bridge-core-sdk";
import * as dotenv from "dotenv";
import { getEnvVar } from "../../../utils/env";
import { ensure } from "../../../utils/utils";
Expand All @@ -25,23 +31,23 @@ const main = async () => {
//check if sending tokens already approved
if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) {
// authorize the bridge to transfer tokens from sender's address
const rawTransactionApprove = await sdk.bridge.rawTxBuilder.approve({
const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({
token: sourceToken,
owner: fromAddress,
});
})) as RawTronTransaction;
const approveReceipt = await sendTrxRawTransaction(rawTransactionApprove);
console.log("Approve transaction receipt", JSON.stringify(approveReceipt, null, 2));
}

// initiate transfer
const rawTransactionTransfer = await sdk.bridge.rawTxBuilder.send({
const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send({
amount: amount,
fromAccountAddress: fromAddress,
toAccountAddress: toAddress,
sourceToken: sourceToken,
destinationToken: destinationToken,
messenger: Messenger.ALLBRIDGE,
});
})) as RawTronTransaction;

const transferReceipt = await sendTrxRawTransaction(rawTransactionTransfer);
console.log("Transfer tokens transaction receipt:", transferReceipt);
Expand Down
16 changes: 11 additions & 5 deletions examples/src/examples/bridge/trx/trx-build-swap-tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AllbridgeCoreSdk, ChainSymbol, SwapParams, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk";
import {
AllbridgeCoreSdk,
ChainSymbol,
SwapParams,
nodeRpcUrlsDefault,
RawTronTransaction,
} from "@allbridge/bridge-core-sdk";
import * as dotenv from "dotenv";
import { getEnvVar } from "../../../utils/env";
import { ensure } from "../../../utils/utils";
Expand All @@ -25,10 +31,10 @@ const main = async () => {
//check if sending tokens already approved
if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) {
// authorize the bridge to transfer tokens from sender's address
const rawTransactionApprove = await sdk.bridge.rawTxBuilder.approve({
const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({
token: sourceToken,
owner: fromAddress,
});
})) as RawTronTransaction;
const approveReceipt = await sendTrxRawTransaction(rawTransactionApprove);
console.log("Approve transaction receipt", JSON.stringify(approveReceipt, null, 2));
}
Expand All @@ -42,11 +48,11 @@ const main = async () => {
destinationToken: destinationToken,
minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken),
};
const rawTransactionTransfer = await sdk.bridge.rawTxBuilder.send(swapParams);
const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send(swapParams)) as RawTronTransaction;

console.log(`Sending ${amount} ${sourceToken.symbol}`);
const txReceipt = await sendTrxRawTransaction(rawTransactionTransfer);
console.log("tx id:", txReceipt.txid);
console.log("txReceipt:", txReceipt);
};

main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const main = async () => {
})) as RawTronTransaction;

const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit);
console.log("Token claim rewards:", txReceipt.txid);
console.log("Token claim rewards txReceipt:", txReceipt);
};

main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const main = async () => {
})) as RawTronTransaction;

const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit);
console.log("Token deposit:", txReceipt.txid);
console.log("Token deposit txReceipt:", txReceipt);
};

main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const main = async () => {
})) as RawTronTransaction;

const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit);
console.log("Token withdraw:", txReceipt.txid);
console.log("Token withdraw txReceipt:", txReceipt);
};

main()
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"timed-cache": "^2.0.0",
"tronweb": "^6.0.0",
"web3": "^4.16.0",
"web3-eth-contract": "^4.7.2"
"web3-eth-contract": "^4.7.2",
"web3-types": "^1.10.0"
},
"jest": {
"transform": {
Expand All @@ -122,5 +123,6 @@
"transformIgnorePatterns": [
"<rootDir>/node_modules/.pnpm/(?!(timed-cache))"
]
}
},
"packageManager": "[email protected]+sha256.9bee59c7313a216722c079c1e22160dea7f88df4e0c3450b1d7b01b882336c6a"
}
Loading

0 comments on commit 812996f

Please sign in to comment.