@ethersproject/abi#TransactionDescription TypeScript Examples
The following examples show how to use
@ethersproject/abi#TransactionDescription.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: transaction.ts From tx2uml with MIT License | 6 votes |
addInputParamsToTrace = (
trace: Trace,
txDescription: TransactionDescription
) => {
// For each function argument, add to the trace input params
txDescription.args.forEach((arg, i) => {
const functionFragment = txDescription.functionFragment.inputs[i]
const components = addValuesToComponents(functionFragment, arg)
trace.inputParams.push({
name: functionFragment.name,
type: functionFragment.type,
value: arg,
components,
})
})
}
Example #2
Source File: transaction.ts From tx2uml with MIT License | 6 votes |
addOutputParamsToTrace = (
trace: Trace,
txDescription: TransactionDescription
): void => {
// Undefined outputs can happen with failed transactions
if (!trace.outputs || trace.outputs === "0x" || trace.error) return
const functionFragments = txDescription.functionFragment.outputs
const outputParams = defaultAbiCoder.decode(
functionFragments,
trace.outputs
)
// For each output, add to the trace output params
outputParams.forEach((param, i) => {
const components = addValuesToComponents(functionFragments[i], param)
trace.outputParams.push({
name: functionFragments[i].name,
type: functionFragments[i].type,
value: param,
components,
})
})
debug(
`Decoded ${trace.outputParams.length} output params for ${trace.funcName} with selector ${trace.funcSelector}`
)
}
Example #3
Source File: commitments.ts From hubble-contracts with MIT License | 6 votes |
static fromCalldata(
txDescription: TransactionDescription,
accountRoot: string
) {
const {
stateRoots,
signatures,
feeReceivers,
txss
} = txDescription.args;
const commitments = [];
for (let i = 0; i < stateRoots.length; i++) {
const commitment = new TransferCommitment(
stateRoots[i],
accountRoot,
signatures[i],
feeReceivers[i],
txss[i]
);
commitments.push(commitment);
}
return new this(commitments);
}
Example #4
Source File: commitments.ts From hubble-contracts with MIT License | 6 votes |
static fromCalldata(
txDescription: TransactionDescription,
accountRoot: string
) {
const {
stateRoots,
signatures,
meta,
withdrawRoots,
txss
} = txDescription.args;
const commitments = [];
for (let i = 0; i < stateRoots.length; i++) {
const [spokeID, tokenID, amount, feeReceiver] = meta[i];
const commitment = new MassMigrationCommitment(
stateRoots[i],
accountRoot,
signatures[i],
spokeID,
withdrawRoots[i],
tokenID,
amount,
feeReceiver,
txss[i]
);
commitments.push(commitment);
}
return new this(commitments);
}
Example #5
Source File: commitments.ts From hubble-contracts with MIT License | 6 votes |
static fromCalldata(
txDescription: TransactionDescription,
accountRoot: string
) {
const {
stateRoots,
signatures,
feeReceivers,
txss
} = txDescription.args;
const commitments = [];
for (let i = 0; i < stateRoots.length; i++) {
const commitment = new Create2TransferCommitment(
stateRoots[i],
accountRoot,
signatures[i],
feeReceivers[i],
txss[i]
);
commitments.push(commitment);
}
return new this(commitments);
}
Example #6
Source File: commitments.ts From hubble-contracts with MIT License | 6 votes |
export function batchFactory(
batchType: Usage,
txDescription: TransactionDescription,
accountRoot: string
): Batch {
if (batchType == Usage.Transfer) {
return TransferBatch.fromCalldata(txDescription, accountRoot);
} else if (batchType == Usage.MassMigration) {
return MassMigrationBatch.fromCalldata(txDescription, accountRoot);
} else if (batchType == Usage.Create2Transfer) {
return MassMigrationBatch.fromCalldata(txDescription, accountRoot);
} else {
throw new Error(`Invalid or unimplemented batchType ${batchType}`);
}
}
Example #7
Source File: buildBridgeTokenTransaction-test.ts From sdk with ISC License | 4 votes |
describe("SynapseBridge - buildBridgeTokenTransaction tests", function(this: Mocha.Suite) {
interface Expected {
wantFn: string,
}
type TestCase = BridgeSwapTestCase<Expected>
const makeTestCase = (
t1: Token, t2: Token,
c1: number, c2: number,
wantFn: string,
): TestCase => {
const expected: Expected = {wantFn};
return makeBridgeSwapTestCase(c1, t1, c2, t2, expected, getTestAmount(t1, c1))
}
function makeTestName(tc: TestCase): string {
let {
args: {
amountFrom,
tokenFrom,
tokenFrom: { symbol: tokFrom },
tokenTo: { symbol: tokTo },
chainIdFrom: chainFrom,
chainIdTo: chainTo,
},
expected: {wantFn}
} = tc;
const
amt = formatUnits(amountFrom, tokenFrom.decimals(chainFrom)),
netFrom = Networks.networkName(chainFrom),
netTo = Networks.networkName(chainTo);
const
testPrefix: string = "buildBridgeTokenTransaction()",
testParamsTitle: string = `with params ${tokFrom} on ${netFrom} -> ${tokTo} on ${netTo}`,
testWant: string = `should be a transaction which calls ${wantFn}()`;
return `${testPrefix} ${testParamsTitle} ${testWant}`
}
const
redeem = "redeem",
deposit = "deposit",
depositETH = "depositETH",
redeemAndSwap = "redeemAndSwap",
redeemAndRemove = "redeemAndRemove",
swapAndRedeemAndRemove = "swapAndRedeemAndRemove",
swapETHAndRedeem = "swapETHAndRedeem",
swapAndRedeem = "swapAndRedeem",
swapETHAndRedeemAndSwap = "swapETHAndRedeemAndSwap",
swapAndRedeemAndSwap = "swapAndRedeemAndSwap",
zapAndDeposit = "zapAndDeposit",
zapAndDepositAndSwap = "zapAndDepositAndSwap",
depositAndSwap = "depositAndSwap",
depositETHAndSwap = "depositETHAndSwap";
[
makeTestCase(Tokens.DAI, Tokens.USDC, ChainId.ETH, ChainId.BSC, zapAndDepositAndSwap),
makeTestCase(Tokens.NETH, Tokens.ETH, ChainId.BOBA, ChainId.ETH, redeem),
makeTestCase(Tokens.NETH, Tokens.NETH, ChainId.BOBA, ChainId.ETH, redeem),
makeTestCase(Tokens.USDC, Tokens.NUSD, ChainId.BOBA, ChainId.BSC, swapAndRedeem),
makeTestCase(Tokens.USDC, Tokens.USDT, ChainId.BSC, ChainId.BOBA, swapAndRedeemAndSwap),
makeTestCase(Tokens.FRAX, Tokens.FRAX, ChainId.MOONRIVER, ChainId.ETH, redeem),
makeTestCase(Tokens.FRAX, Tokens.FRAX, ChainId.ETH, ChainId.MOONRIVER, deposit),
makeTestCase(Tokens.SYN, Tokens.SYN, ChainId.MOONRIVER, ChainId.ETH, redeem),
makeTestCase(Tokens.SYN, Tokens.SYN, ChainId.ETH, ChainId.MOONRIVER, redeem),
makeTestCase(Tokens.ETH, Tokens.NETH, ChainId.OPTIMISM, ChainId.ETH, swapETHAndRedeem),
makeTestCase(Tokens.ETH, Tokens.NETH, ChainId.ETH, ChainId.AVALANCHE, depositETH),
makeTestCase(Tokens.WETH_E, Tokens.ETH, ChainId.AVALANCHE, ChainId.ETH, swapAndRedeem),
makeTestCase(Tokens.WETH_E, Tokens.ETH, ChainId.AVALANCHE, ChainId.ARBITRUM, swapAndRedeemAndSwap),
makeTestCase(Tokens.ETH, Tokens.WETH_E, ChainId.ETH, ChainId.AVALANCHE, depositETHAndSwap),
makeTestCase(Tokens.NUSD, Tokens.DAI, ChainId.AVALANCHE, ChainId.ETH, redeemAndRemove),
makeTestCase(Tokens.DAI, Tokens.DAI, ChainId.AVALANCHE, ChainId.ETH, swapAndRedeemAndRemove),
makeTestCase(Tokens.NUSD, Tokens.DAI, ChainId.AVALANCHE, ChainId.POLYGON, redeemAndSwap),
makeTestCase(Tokens.DOG, Tokens.DOG, ChainId.POLYGON, ChainId.ETH, redeem),
makeTestCase(Tokens.ETH, Tokens.ETH, ChainId.ARBITRUM, ChainId.OPTIMISM, swapETHAndRedeemAndSwap),
makeTestCase(Tokens.NETH, Tokens.ETH, ChainId.ARBITRUM, ChainId.OPTIMISM, redeemAndSwap),
makeTestCase(Tokens.JUMP, Tokens.JUMP, ChainId.FANTOM, ChainId.BSC, deposit),
makeTestCase(Tokens.GOHM, Tokens.GOHM, ChainId.AVALANCHE, ChainId.OPTIMISM, redeem),
makeTestCase(Tokens.GOHM, Tokens.GOHM, ChainId.ETH, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.GOHM, Tokens.GOHM, ChainId.HARMONY, ChainId.MOONRIVER, redeem),
makeTestCase(Tokens.GOHM, Tokens.GOHM, ChainId.ETH, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.USDC, Tokens.USDC, ChainId.AURORA, ChainId.AVALANCHE, swapAndRedeemAndSwap),
makeTestCase(Tokens.USDC, Tokens.NUSD, ChainId.BSC, ChainId.AURORA, swapAndRedeem),
makeTestCase(Tokens.USDC, Tokens.NUSD, ChainId.AURORA, ChainId.ETH, swapAndRedeem),
makeTestCase(Tokens.USDC, Tokens.NUSD, ChainId.ETH, ChainId.AURORA, zapAndDeposit),
makeTestCase(Tokens.WETH, Tokens.WETH_E, ChainId.ETH, ChainId.AVALANCHE, depositETHAndSwap),
makeTestCase(Tokens.NUSD, Tokens.NUSD, ChainId.ETH, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.WETH_E, Tokens.WETH, ChainId.AVALANCHE, ChainId.OPTIMISM, swapAndRedeemAndSwap),
makeTestCase(Tokens.WETH, Tokens.ONE_ETH, ChainId.ETH, ChainId.HARMONY, depositETHAndSwap),
makeTestCase(Tokens.ONE_ETH, Tokens.WETH_E, ChainId.HARMONY, ChainId.AVALANCHE, swapAndRedeemAndSwap),
makeTestCase(Tokens.HIGH, Tokens.HIGH, ChainId.BSC, ChainId.ETH, redeem),
makeTestCase(Tokens.JUMP, Tokens.JUMP, ChainId.BSC, ChainId.FANTOM, redeem),
makeTestCase(Tokens.DOG, Tokens.DOG, ChainId.BSC, ChainId.POLYGON, redeem),
makeTestCase(Tokens.NFD, Tokens.NFD, ChainId.POLYGON, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.GMX, Tokens.GMX, ChainId.ARBITRUM, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.GMX, Tokens.GMX, ChainId.AVALANCHE, ChainId.ARBITRUM, redeem),
makeTestCase(Tokens.SOLAR, Tokens.SOLAR, ChainId.MOONRIVER, ChainId.MOONBEAM, deposit),
makeTestCase(Tokens.WAVAX, Tokens.AVAX, ChainId.MOONBEAM, ChainId.AVALANCHE, redeem),
makeTestCase(Tokens.AVAX, Tokens.WAVAX, ChainId.AVALANCHE, ChainId.MOONBEAM, depositETH),
makeTestCase(Tokens.WMOVR, Tokens.MOVR, ChainId.MOONBEAM, ChainId.MOONRIVER, redeem),
makeTestCase(Tokens.MOVR, Tokens.WMOVR, ChainId.MOONRIVER, ChainId.MOONBEAM, depositETH),
makeTestCase(Tokens.FTM_ETH, Tokens.WETH, ChainId.FANTOM, ChainId.ETH, swapAndRedeem),
makeTestCase(Tokens.FTM_ETH, Tokens.ETH, ChainId.FANTOM, ChainId.ETH, swapAndRedeem),
makeTestCase(Tokens.FTM_ETH, Tokens.WETH_E, ChainId.FANTOM, ChainId.AVALANCHE, swapAndRedeemAndSwap),
makeTestCase(Tokens.WETH_E, Tokens.FTM_ETH, ChainId.AVALANCHE, ChainId.FANTOM, swapAndRedeemAndSwap),
makeTestCase(Tokens.ETH, Tokens.FTM_ETH, ChainId.ETH, ChainId.FANTOM, depositETHAndSwap),
makeTestCase(Tokens.WETH, Tokens.FTM_ETH, ChainId.ETH, ChainId.FANTOM, depositETHAndSwap),
makeTestCase(Tokens.ETH, Tokens.WETH_E, ChainId.ARBITRUM, ChainId.AVALANCHE, swapETHAndRedeemAndSwap),
makeTestCase(Tokens.WETH, Tokens.WETH_E, ChainId.ARBITRUM, ChainId.AVALANCHE, swapETHAndRedeemAndSwap),
makeTestCase(Tokens.WETH_E, Tokens.ETH, ChainId.AVALANCHE, ChainId.ARBITRUM, swapAndRedeemAndSwap),
makeTestCase(Tokens.WETH_E, Tokens.WETH, ChainId.AVALANCHE, ChainId.ARBITRUM, swapAndRedeemAndSwap),
makeTestCase(Tokens.USDC, Tokens.DAI, ChainId.BSC, ChainId.ETH, swapAndRedeemAndRemove),
makeTestCase(Tokens.NUSD, Tokens.DAI, ChainId.BSC, ChainId.ETH, redeemAndRemove),
makeTestCase(Tokens.NUSD, Tokens.USDC, ChainId.ETH, ChainId.BSC, depositAndSwap),
makeTestCase(Tokens.NUSD, Tokens.NUSD, ChainId.BSC, ChainId.POLYGON, redeem),
makeTestCase(Tokens.NUSD, Tokens.NUSD, ChainId.POLYGON, ChainId.BSC, redeem),
makeTestCase(Tokens.UST, Tokens.UST, ChainId.BSC, ChainId.POLYGON, redeem),
makeTestCase(Tokens.UST, Tokens.UST, ChainId.POLYGON, ChainId.ETH, redeem),
makeTestCase(Tokens.NEWO, Tokens.NEWO, ChainId.ARBITRUM, ChainId.AVALANCHE, redeem),
makeTestCase(Tokens.NEWO, Tokens.NEWO, ChainId.ETH, ChainId.AVALANCHE, deposit),
makeTestCase(Tokens.NEWO, Tokens.NEWO, ChainId.AVALANCHE, ChainId.ETH, redeem),
makeTestCase(Tokens.SDT, Tokens.SDT, ChainId.ETH, ChainId.FANTOM, deposit),
makeTestCase(Tokens.SDT, Tokens.SDT, ChainId.AVALANCHE, ChainId.HARMONY, redeem),
makeTestCase(Tokens.SDT, Tokens.SDT, ChainId.FANTOM, ChainId.HARMONY, redeem),
makeTestCase(Tokens.SDT, Tokens.SDT, ChainId.AVALANCHE, ChainId.FANTOM, redeem),
makeTestCase(Tokens.LUNA, Tokens.LUNA, ChainId.ARBITRUM, ChainId.OPTIMISM, redeem),
makeTestCase(Tokens.LUNA, Tokens.LUNA, ChainId.OPTIMISM, ChainId.ARBITRUM, redeem),
makeTestCase(Tokens.METIS_ETH, Tokens.WETH_E, ChainId.METIS, ChainId.AVALANCHE, swapAndRedeemAndSwap),
makeTestCase(Tokens.ETH, Tokens.METIS_ETH, ChainId.ETH, ChainId.METIS, depositETHAndSwap),
makeTestCase(Tokens.NETH, Tokens.WETH_E, ChainId.METIS, ChainId.AVALANCHE, redeemAndSwap),
].forEach((tc: TestCase) => {
const testTitle = makeTestName(tc);
describe(testTitle, function(this: Mocha.Suite) {
let builtTxn: PopulatedTransaction;
const amountTo = tc.args.amountFrom.sub(5);
step("build transaction", async function(this: Mocha.Context) {
this.timeout(DEFAULT_TEST_TIMEOUT);
let {args: { chainIdFrom }, args} = tc;
const
bridgeInstance = new Bridge.SynapseBridge({ network: chainIdFrom }),
addressTo: string = makeWalletSignerWithProvider(chainIdFrom, bridgeTestPrivkey1).address;
let prom = bridgeInstance.buildBridgeTokenTransaction({...args, amountTo, addressTo});
Promise.resolve(prom).then(built => builtTxn = built);
return (await expectFulfilled(prom))
})
let txnInfo: TransactionDescription;
const
l1BridgeZapInterface = L1BridgeZapFactory.createInterface(),
l2BridgeZapInterface = L2BridgeZapFactory.createInterface();
step(`tx should be a call to function ${tc.expected.wantFn}()`, function(this: Mocha.Context) {
txnInfo = tc.args.chainIdFrom === ChainId.ETH
? l1BridgeZapInterface.parseTransaction({data: builtTxn.data || ""})
: l2BridgeZapInterface.parseTransaction({data: builtTxn.data || ""});
expect(txnInfo.name).to.equal(tc.expected.wantFn);
});
});
});
});