-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(wip): add gift wallet support * fix: fix gift wallet flows * build: add missing dependency * feat: add swap * feat: add cloudflare resolver to config
- Loading branch information
Showing
10 changed files
with
2,094 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { JsonRpcProvider } from '@ethersproject/providers' | ||
import { BigNumber, Contract, providers, Wallet } from 'ethers' | ||
import { bzzContractInterface } from './contract' | ||
|
||
export async function sendNativeTransaction( | ||
privateKey: string, | ||
address: string, | ||
amount: string, | ||
providerHost: string, | ||
): Promise<providers.TransactionResponse> { | ||
const provider = new JsonRpcProvider(providerHost, 100) | ||
await provider.ready | ||
const signer = new Wallet(privateKey, provider) | ||
const gasPrice = await signer.getGasPrice() | ||
|
||
return signer.sendTransaction({ | ||
to: address, | ||
value: amount, | ||
gasPrice, | ||
}) | ||
} | ||
|
||
export async function sendBzzTransaction( | ||
privateKey: string, | ||
address: string, | ||
amount: string, | ||
providerHost: string, | ||
): Promise<providers.TransactionResponse> { | ||
const provider = new JsonRpcProvider(providerHost, 100) | ||
await provider.ready | ||
const signer = new Wallet(privateKey, provider) | ||
const bzz = new Contract('0xdBF3Ea6F5beE45c02255B2c26a16F300502F68da', bzzContractInterface, signer) | ||
const gasPrice = await signer.getGasPrice() | ||
|
||
return bzz.transfer(address, BigNumber.from(amount), { gasPrice }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const bzzContractInterface = [ | ||
{ | ||
type: 'function', | ||
stateMutability: 'nonpayable', | ||
payable: false, | ||
outputs: [ | ||
{ | ||
type: 'bool', | ||
name: '', | ||
}, | ||
], | ||
name: 'transfer', | ||
inputs: [ | ||
{ | ||
type: 'address', | ||
name: '_to', | ||
}, | ||
{ | ||
type: 'uint256', | ||
name: '_value', | ||
}, | ||
], | ||
constant: false, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Contract, ethers, providers } from 'ethers' | ||
|
||
const contractInterface = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: 'amountOutMin', | ||
type: 'uint256', | ||
}, | ||
{ | ||
internalType: 'address[]', | ||
name: 'path', | ||
type: 'address[]', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
internalType: 'uint256', | ||
name: 'deadline', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'swapExactETHForTokens', | ||
outputs: [ | ||
{ | ||
internalType: 'uint256[]', | ||
name: 'amounts', | ||
type: 'uint256[]', | ||
}, | ||
], | ||
stateMutability: 'payable', | ||
type: 'function', | ||
}, | ||
] | ||
|
||
export async function swap( | ||
privateKey: string, | ||
xdai: string, | ||
minimumBzz: string, | ||
jsonRpcProvider: string, | ||
): Promise<string[]> { | ||
const provider = new providers.JsonRpcProvider(jsonRpcProvider, 100) | ||
const signer = new ethers.Wallet(privateKey, provider) | ||
const gasLimit = 1000000 | ||
const contract = new Contract('0x1C232F01118CB8B424793ae03F870aa7D0ac7f77', contractInterface, signer) | ||
const WRAPPED_XDAI_CONTRACT = '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d' | ||
const BZZ_ON_XDAI_CONTRACT = '0xdbf3ea6f5bee45c02255b2c26a16f300502f68da' | ||
const response = await contract.swapExactETHForTokens( | ||
minimumBzz, | ||
[WRAPPED_XDAI_CONTRACT, BZZ_ON_XDAI_CONTRACT], | ||
await signer.getAddress(), | ||
Date.now(), | ||
{ | ||
value: xdai, | ||
gasLimit, | ||
}, | ||
) | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export async function wait(ms: number): Promise<void> { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, ms) | ||
}) | ||
} |