0.6.8 • Published 8 months ago

@wallchain/sdk v0.6.8

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

Wallchain SDK

Simple integration to get MEV cashback.

1. Create SDK instance

import { SDK } '@wallchain/sdk';

const wallchain = new SDK({
    provider //EIP-1193 provider
    keys: {
        matic: 'key',
        ...
        /* 
            Api keys to Wallchain's contract.
            Don't have keys? Contact our sales team.
        */
    },
    originator?: [] // platform addresses to recieve reward
    originShare?: 0 //percent that you share with user, originShare ∈ [0, 50]
})

2. Check for MEV oppurtunity

const transactionData = {
    from:  'address',
    to:    'address',
    data:  'bytes',
    value: 'uint',
}

const apiResponse = await wallchain.checkMEV(transactionData);

In case MEV is found response will be shaped this way:

{
    MEVFound: true,
    cahsbackAmount: string, // in usd
    masterInput: string
}

Or sad version of it:

{
    MEVFound: false
}

3. Allowance

Permit2 technology is being used to withdraw ERC-20 for executing the swap. No need to ask for permit if swapping native token of the chain.

const hasAllowance = await sdk.hasEnoughAllowance(sourceTokenAddress, ownerAddress, amount);

if (!hasAllowance) {
    // returns Permit2 if chain supports, fallbacks to Wallchain contract
    const spenderForAllowance = await sdk.getSpenderForAllowance();

}

4. Permit

In case user swaps ERC-20 token, we'd need to ask for a permit to execute the swap itself.

const spender = await sdk.getSpender();  // Wallchain's address at current chain
const witness = await sdk.signPermit(tokenAddress, wallet, spender, value);

This function automaticaly calls the wallet and resolves with signature and signed data.

5. Update transaction

const newTransaction = await sdk.createNewTransaction(
    {
        ...originalTransaction,
        isPermit, // true if not native token
        amountIn, // amount of token to swap, equals msg.value when native token
        srcTokenAddress,
        dstTokenAddress
    },
    apiResp.masterInput  // Resolved on step #1
    witness,  // resolved from step #4 or undefined
)


type newTransaction: {
    from: string,
    to: string,
    data: string,
    value: string,
    gas: string
}

Now you can send it safe and secure.

0.6.7

8 months ago

0.6.6

8 months ago

0.6.8

8 months ago

0.6.3

8 months ago

0.5.4

10 months ago

0.6.2

9 months ago

0.5.3

10 months ago

0.6.5

8 months ago

0.5.6

10 months ago

0.6.4

8 months ago

0.5.5

10 months ago

0.6.1

9 months ago

0.5.2

10 months ago

0.6.0

9 months ago

0.5.1

10 months ago

0.5.0

11 months ago